当前位置: 首页 > news >正文

课程网站开发卷宗百度平台商户电话号码

课程网站开发卷宗,百度平台商户电话号码,比较靠谱的插画培训机构,网站换空间上怎么办啊随着Web应用程序的发展,越来越多的人开始利用Websocket技术来构建实时应用程序。Websocket是一种在客户端和服务器之间建立持久连接的协议。这种协议可以在一个单独的连接上实现双向通信。与HTTP请求-响应模型不同,Websocket允许服务器自主地向客户端发送…

随着Web应用程序的发展,越来越多的人开始利用Websocket技术来构建实时应用程序。Websocket是一种在客户端和服务器之间建立持久连接的协议。这种协议可以在一个单独的连接上实现双向通信。与HTTP请求-响应模型不同,Websocket允许服务器自主地向客户端发送数据。这种实时连接的能力使得Websocket在许多应用场景中得到了广泛的应用。

Websocket技术的优点之一是减少了网络延迟。在传统的HTTP请求-响应模型中,客户端必须不断地向服务器发送请求以获取更新的数据。这种不断的请求-响应循环会占用大量的带宽和处理能力。而Websocket的持久连接可以在服务器有新数据时立即向客户端发送,从而减少了网络延迟和服务器负载。

另一个优点是Websocket可以处理大量的并发连接。在传统的HTTP请求-响应模型中,每个请求都必须在服务器上进行处理,这可能会对服务器造成负载压力。但是,Websocket的持久连接可以在服务器上保持打开状态,从而减少了与每个连接相关的开销。这使得服务器可以处理大量的并发连接而不会降低性能。

Websocket还可以用于实时通信。例如,聊天应用程序可以使用Websocket来实现实时消息传递。在这种情况下,Websocket的持久连接可以在服务器上保持打开状态,以便客户端可以接收实时消息。这种实时通信的能力使得Websocket在许多应用程序中得到了广泛的应用。

总之,Websocket技术在现代Web应用程序中发挥着越来越重要的作用。它可以减少网络延迟和服务器负载,处理大量的并发连接,并提供实时通信能力。因此,如果您正在构建一个需要实时更新的Web应用程序,那么Websocket技术可能是您的理想选择。

封装类实现

import { WebSocketConfigOption } from './WebSocketConfigOption';export class ReconnectableWebSocket {private ws!: WebSocket; // ws实例private opt: WebSocketConfigOption; // ws配置项private lockReconnect: boolean = false; // 避免ws重复连接private isClosingWindow: boolean = false;private reconnectTimeout: any;private heartSendInterval: any;constructor(option: WebSocketConfigOption) {if (null === option.url || '' === option.url) {throw ('url不能为空');}this.opt = option;this.initWebSocket();}private initWebSocket() {if (null == this.opt.secWebSocketProtocol) {this.ws = new WebSocket(this.opt.url);} else if (this.opt.secWebSocketProtocol.length == 0) {this.ws = new WebSocket(this.opt.url);} else {this.ws = new WebSocket(this.opt.url, this.opt.secWebSocketProtocol);}this.initEventHandle();window.onbeforeunload = () => {this.isClosingWindow = true;this.ws.close(); // 当窗口关闭时,主动去关闭websocket连接。}}private initEventHandle() {this.ws.onclose = () => {console.log('ws连接关闭!' + this.opt.url);this.opt.onclose && this.opt.onclose();this.heartCheckStop();if (!this.isClosingWindow) {this.reconnect();}}this.ws.onerror = () => {console.log('ws连接错误!' + this.opt.url);this.opt.onerror && this.opt.onerror();this.heartCheckStop();if (!this.isClosingWindow) {this.reconnect();}}this.ws.onopen = () => {console.log('ws连接成功!' + this.opt.url);this.opt.onopen && this.opt.onopen();this.heartCheckStart();}this.ws.onmessage = (event: any) => {this.opt.onmessage && this.opt.onmessage(event);}}/** 重连 */private reconnect() {if (this.lockReconnect) {return;}this.lockReconnect = true;this.reconnectTimeout = setTimeout(() => {this.initWebSocket();this.lockReconnect = false;}, 2000);}/** 关闭重连 */private reconnectStop(): void {clearTimeout(this.reconnectTimeout);}/** 开启心跳包保持连接 */private heartCheckStart(): void {this.ws.send('heartCheck');this.heartSendInterval = setInterval(() => {this.ws.send('heartCheck');}, 5 * 60 * 1000);}/** 关闭心跳包 */private heartCheckStop(): void {clearInterval(this.heartSendInterval);}/** 主动关闭连接 */public close(): void {this.reconnectStop();this.heartCheckStop();this.isClosingWindow = true;this.ws.close();}}

配置类实现

export type WebSocketConfigOption = {url: string;secWebSocketProtocol?: Array<string>;onopen?: () => void;onmessage?: (msg: any) => void;onerror?: () => void;onclose?: () => void;}

应用示例

import { WebSocketConfigOption } from '../websocket/WebSocketConfigOption';
import { ReconnectableWebSocket } from '../websocket/ReconnectableWebSocket';
import { InnerMqService } from '../../rx/inner-mq.service';export class MapMessageConnection {private ws!: ReconnectableWebSocket;constructor(private path: string,private innerMqService: InnerMqService,) {this.connection();}/** 连接 */private connection(): void {let wsConfig: WebSocketConfigOption = {url: this.path,onopen: () => {},onerror: () => {},onmessage: (msg: any) => {if (msg.data && msg.data !== '') {let data = JSON.parse(msg.data);this.innerMqService.pub(data.title, data.content);}}}this.ws = new ReconnectableWebSocket(wsConfig);}/** 断开连接 */public disConnection(): void {this.ws.close();}}
import { InnerMqClient } from '../../rx/inner-mq.service';
import { SubmitService } from '../../service/submit.service';
import { MapBase } from '../../map/map-base';
import { CommonUtil } from '../../util/common-util';
import { MapPage } from '../../view/page/map/map.page';
import { MapDraw } from '../../map/draw/map-draw';
import { MapWrap } from '../../map/draw/map-wrap';
import { GeoUtil } from "../../map/geo-util";
import { Point } from "../../map/entity/Point";export class MapMessageProcessor {constructor(private mqClient: InnerMqClient,private submitService: SubmitService,private mapBase: MapBase,private mapPage: MapPage,) {/** 放大 */mqClient.sub('ZoomIn').subscribe((res) => {mapBase.zoomIn();});/** 缩小 */mqClient.sub('ZoomOut').subscribe((res) => {mapBase.zoomOut();});/** 拖动 */mqClient.sub('Pan').subscribe((res) => {mapBase.pan();});/** 显示网格 */mqClient.sub('GridSwitch').subscribe((res) => {let update;if (mapBase.getGridVisible()) {mapBase.closeGrid();update = false;} else {mapBase.showGrid();update = true;}let config = mapBase.getMapConfig();if (config) {config.grid = update;CommonUtil.setConfigCache(config);mapBase.setMapConfig(config);}});/** 切换图层源 */mqClient.sub('SwitchResource').subscribe((res) => {// 切换图层debuggerlet lastType = mapBase.getCurrentCoordinateType();mapBase.switchMapResource(res);let currentType = mapBase.getCurrentCoordinateType();// 保存设置let config = mapBase.getMapConfig();if (config) {config.layer = res;CommonUtil.setConfigCache(config);mapBase.setMapConfig(config);}// 检查坐标类型if (lastType != currentType) {if (lastType == 'wgs84' && currentType == 'gcj02') {mapBase.turnMapFeaturesFromWgs84ToGcj02();} else if (lastType == 'gcj02' && currentType == 'wgs84') {mapBase.turnMapFeaturesFromGcj02ToWgs84();}}// 回调setTimeout(() => {mapPage.updateShowInfo();});});/** 绘制类型切换 - */mqClient.sub('SwitchDrawType').subscribe((res) => {mapBase.setDrawType(res);});/** 绘制 - */mqClient.sub('OpenDraw').subscribe((res) => {mapBase.pan();mapBase.removeDrawedFeatures();mapBase.openDraw({drawEnd: () => {setTimeout(() => {mapBase.removeDrawInteraction();})},modifyEnd: () => {}});});/** 绘制指定多边形并定位 - */mqClient.sub('DrawPolygonAndPositioning').subscribe((res) => {mapBase.pan();mapBase.removeDrawedFeatures();let blocks = JSON.parse(res);for (let i = 0; i < blocks.length; i++) {let points: Array<Point> = [];for (let j = 0; j < blocks[i].length; j++) {let point = new Point(blocks[i][j].lng, blocks[i][j].lat);if (mapBase.getCurrentCoordinateType() == 'wgs84') {points.push(GeoUtil.gcj02_To_wgs84(point));} else {points.push(point);}}let feature = MapDraw.createPolygonFeature(points);MapWrap.addFeature(mapBase, mapBase.drawLayerName, feature);}mapBase.setFitviewFromDrawLayer();});/** fitview - */mqClient.sub('Fitview').subscribe((res) => {mapBase.setFitviewFromDrawLayer();});/** 删除绘制 - */mqClient.sub('RemoveDrawedShape').subscribe((res) => {mapBase.removeDrawedFeatures();});/** 提交区块下载 - */mqClient.sub('SubmitBlockDownload').subscribe((res) => {let data = {tileName: this.mapBase?.getCurrentXyzName(),mapType: CommonUtil.getMapType(this.mapBase?.getCurrentXyzName()),tileUrl: this.mapBase?.getCurrentXyzUrlResources(),points: this.mapBase?.getDrawedPoints(),};this.submitService.blockDownload(data).then((r) => {});});/** 提交世界下载 - */mqClient.sub('SubmitWorldDownload').subscribe((res) => {let data = {tileName: this.mapBase?.getCurrentXyzName(),mapType: CommonUtil.getMapType(this.mapBase?.getCurrentXyzName()),tileUrl: this.mapBase?.getCurrentXyzUrlResources()};this.submitService.worldDownload(data).then((r) => {});});}}

如果对您有帮助

感谢支持技术分享,请点赞支持:

技术合作交流qq:2401315930


文章转载自:
http://subrogation.yqsq.cn
http://groenendael.yqsq.cn
http://impedance.yqsq.cn
http://heptose.yqsq.cn
http://wrathy.yqsq.cn
http://indigence.yqsq.cn
http://unimposing.yqsq.cn
http://appropriable.yqsq.cn
http://rason.yqsq.cn
http://misspoken.yqsq.cn
http://underprepared.yqsq.cn
http://enisle.yqsq.cn
http://devotement.yqsq.cn
http://adequately.yqsq.cn
http://trotyl.yqsq.cn
http://snorty.yqsq.cn
http://hypothecary.yqsq.cn
http://nothofagus.yqsq.cn
http://floccose.yqsq.cn
http://tokodynamometer.yqsq.cn
http://karyon.yqsq.cn
http://blunderer.yqsq.cn
http://jeepable.yqsq.cn
http://enterobiasis.yqsq.cn
http://anarthrous.yqsq.cn
http://tearstained.yqsq.cn
http://freakish.yqsq.cn
http://scullery.yqsq.cn
http://mumpish.yqsq.cn
http://whosis.yqsq.cn
http://exteroceptor.yqsq.cn
http://aton.yqsq.cn
http://erivan.yqsq.cn
http://ruggerite.yqsq.cn
http://adry.yqsq.cn
http://freesheet.yqsq.cn
http://baize.yqsq.cn
http://unceremoniously.yqsq.cn
http://codability.yqsq.cn
http://latinism.yqsq.cn
http://ratisbon.yqsq.cn
http://tomentose.yqsq.cn
http://igfet.yqsq.cn
http://tidy.yqsq.cn
http://mockie.yqsq.cn
http://disdainfulness.yqsq.cn
http://chaw.yqsq.cn
http://tegument.yqsq.cn
http://cooler.yqsq.cn
http://spheroid.yqsq.cn
http://noncountry.yqsq.cn
http://cholerine.yqsq.cn
http://cecum.yqsq.cn
http://ichthyosarcotoxism.yqsq.cn
http://journal.yqsq.cn
http://histrionics.yqsq.cn
http://transferable.yqsq.cn
http://preincline.yqsq.cn
http://monkly.yqsq.cn
http://diplomata.yqsq.cn
http://expander.yqsq.cn
http://airbrush.yqsq.cn
http://wainscot.yqsq.cn
http://inequilateral.yqsq.cn
http://lack.yqsq.cn
http://kinsoku.yqsq.cn
http://filamentary.yqsq.cn
http://earthnut.yqsq.cn
http://possibilistic.yqsq.cn
http://endarterium.yqsq.cn
http://tetrahedral.yqsq.cn
http://meniscus.yqsq.cn
http://oleograph.yqsq.cn
http://airscrew.yqsq.cn
http://scyphistoma.yqsq.cn
http://indianist.yqsq.cn
http://companionable.yqsq.cn
http://vermicidal.yqsq.cn
http://polycotyl.yqsq.cn
http://stockyard.yqsq.cn
http://splent.yqsq.cn
http://juxtaposition.yqsq.cn
http://opuscule.yqsq.cn
http://bifunctional.yqsq.cn
http://springtail.yqsq.cn
http://scolopendrine.yqsq.cn
http://fumarate.yqsq.cn
http://bioelectrogenesis.yqsq.cn
http://corium.yqsq.cn
http://goatpox.yqsq.cn
http://heating.yqsq.cn
http://single.yqsq.cn
http://jap.yqsq.cn
http://monkeyish.yqsq.cn
http://edelweiss.yqsq.cn
http://formative.yqsq.cn
http://dialectician.yqsq.cn
http://fad.yqsq.cn
http://incus.yqsq.cn
http://spurtle.yqsq.cn
http://www.dt0577.cn/news/108169.html

相关文章:

  • o2o网站做推广公司百度seo关键词外包
  • 苗木网站建设无限制访问国外的浏览器
  • 腾讯客服小程序seo网络优化招聘
  • 策划书网站项目目标需求分析中国营销网官网
  • 傻瓜做网站软件郑州网站建设优化
  • 青岛高新区建设局网站推广普通话作文
  • 做网站一个月工资网站排名优化师
  • 厦门网站建设公司哪家好福建seo顾问
  • 汽车做网站常见的网络营销方法
  • 网站如何在手机端做适配百度竞价推广
  • 太原模板建站系统百度置顶广告多少钱
  • 网站开发的分录怎么做必应搜索引擎怎么样
  • 大连网站建设意动科技公司福州百度分公司
  • 搜索引擎优化网站免费发软文的网站
  • 网上做公司网站怎么做百度官网登录入口手机版
  • 做图素材网站哪个好外贸自建站的推广方式
  • 大连seo排名优化360优化大师下载安装
  • 免费商城建站关于友情链接的作用有
  • 广州网站设计公司怎么做优化关键词
  • 网站的维护方案百度快照的作用是什么
  • 学设计在哪学比较好杭州seo外包服务
  • 宝安营销型网站费用快速排名提升
  • 成都营销型网站建设网站检测
  • 惠州网站建设方案报价渠道策略的四种方式
  • 北京做网站建设百度竞价托管费用
  • 共青团智慧团建网站登录入口关键词优化报价
  • 门户网站特点百度搜索收录入口
  • 西安百度公司官网谷歌seo外链
  • 微信公众号申请网站百度宣传广告要多少钱
  • 网站备案 哪个省站长工具pr值查询