浅析即时通讯开发WebSocket热门疑问

探索Go语言中高效易用的WebSocket库:Melody与GoWebsocket实战对比 本文深入对比了Go语言中两大高效WebSocket库Melody与GoWebsocket的核心特性与实战应用。Melody以其与Gin框架的无缝集成、自动心跳处理和会话管理功能成为服务端开发首选,而GoWebsocket则在客户端功能如数据压缩和代理支持上表现突出。文章通过性能测试和实际案例,为开发者提供了清晰的选型指南和优化技巧,助力构建高性能实时应用。 阅读详情

WebSocket是一种比较新的协议,它是伴随着html5规范而生的,虽然还比较年轻,但大多主流浏览器都已经支持。它使用方便、应用广泛,已经渗透到前后端开发的各种场景中。

对http一问一答中二式流程(就是从所周之的“长轮询”技要啦)的不满,催生了支持双向通信的WebSocket诞生。WebSocket是个不太干净协议。

 

1问WebSocket:WebSocket协议只能浏览器发起么?

不是。目前此协议的受众的也不仅仅是web开发者。

WebSocket只是一种协议,它和http协议一样,使用类似okhttp的组件,可以在任何地方进行调用,甚至可以借助WebSocket实现RPC框架。

2问WebSocket:WebSocket和HTTP什么关系?

WebSocket和http一样,都是处于OSI模型中的最高层:应用层。

WebSocket借助http协议进行握手,握手成功后,就会变身为TCP通道,从此与http不再相见。

使用netstat或者ss,能够看到对应的连接,它与处于抽象层的socket,在外观上没有区别。

3问WebSocket:WebSocket和长轮询有什么区别?

长轮询,就是客户端发送一个请求,服务端将一直在这个连接上等待(当然有一个超长的超时时间),直到有数据才返回,它依然是一个一问一答的模式。比如著名的comted。

WebSocket在握手成功后,就是全双工的TCP通道,数据可以主动从服务端发送到客户端,处于连接两端的应用没有任何区别。

WebSocket创建的连接和Http的长连接是不一样的。由于Http长连接底层依然是Http协议,所以它还是一问一答,只是Hold住了一条命长点的连接而已

Android 通过WebSocket实现IM功能那些坑 前不久在项目中实现了Im功能,之前im功能使用使用第三方,这次用到了WebSocket。找到https://github.com/TooTallNate/Java-WebSocketcompile "org.java-websocket:Java-WebSocket:1.3.7"基于库实现过程遇到不少问题:坑1:WebSocketClient objects are not reuseable  ... 阅读详情

相关推荐

Spring Boot + WebSocket 实现 IM 即时通讯

通过Spring Boot和WebSocket,可以快速构建一个高效的即时通讯系统。本文介绍了基本的配置和实现流程,并提供了一个简单的示例。即时通讯(IM)已经成为现代应用中不可或缺的一部分,从社交媒体到企业协作工具,无不依赖于IM技术来实现实时消息传递。首先,我们需要创建一个Spring Boot项目,并添加WebSocket的相关依赖。打开多个浏览器窗口或标签页,可以在它们之间发送消息,验证即时通讯功能是否正常工作。接下来,我们需要创建一个控制器来处理WebSocket消息。

学IT,找陈寒 9800

浅析即时通讯开发中HTTP与WebSocket的关系

如果你使用Socket来建立TCP的长连接(2),那么,这个长连接(2)跟我们这里要讨论的WebSocket是一样的,实际上TCP长连接就是WebSocket的基础,但是如果是HTTP的长连接,本质上还是Request/Response消息对,仍然会造成资源的浪费、实时性不强等问题。出于兼容性的考虑,WS的握手使用HTTP来实现(此文档中提到未来有可能会使用专用的端口和方法来实现握手),客户端的握手消息就是一个「普通的,带有Upgrade头的,HTTP Request消息」。...

蔚可云的博客 1023

IM即时通讯开发WebSocket从入门到精通

自从HTML5里的WebSocket出现后,彻底改变了以往Web端即时通讯技术的基础通道这个“痛点”(在此之前,开发者们不得不弄出了诸如:短轮询、长轮询、Comet、SSE等技术,可谓苦之久矣...),如今再也不用纠结到底该用“轮询”还是“Comet”技术来保证数据的实时性了,幸福来的就是如此突然 ^-^。过了握手阶段后,就只能采用特定的错误码。4)Sec-WebSocket-Key:与后面服务端响应首部的Sec-WebSocket-Accept是配套的,提供基本的防护,比如恶意的连接,或者无意的连接。..

蔚可云的博客 621

websocket netty 实现点对点聊天(即时通讯)

websocket netty 实现点对点聊天(即时通讯) 效果图 首先用h5画一个简单的聊天页面,分别录入发送人的id,接受者的id,和需要发的消息,以及消息展示框 然后分别用小明,小红和小刚登录 现在小明给小红发消息,小红收的到,但小刚收不到实现点对点聊天 首先,先看前台代码 h5 <body> <div id="cont...

weixin_39168678的博客 2万+

Springboot集成WebSocket实现即时通讯

在SpringBoot的pom.xml文件里添加依赖: <!-- websocket --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> 在配置中加入 WebSocket...

m0_52348758的博客 4531

WebSocket实时通讯

WebSocket实时通讯(简单Deom)。可以直接运行。无须修改东西。如有问题可以直接联系。

【SOFA】SOFA框架+Win10+VS2019 配置

SOFA (Simulation Open Framework Architecture)官网 SOFA 是一个开源的仿真框架,用于实时的物理仿真,而且主要针对医学上的仿真。主要用于研究人员开发新的算法,也可以作为一个有效的快速成型工具或是物理引擎。 官网中给出的配置方法写的很清晰,有着各个库或者软件的版本要求,仔细看按版本要求来 官网配置地址 官网给了两种方 1.通过脚本自动配置 2. 自己下载相关库通过CMake进行生成 第一种 没使用,不知道是否好使,因为如果其中有下载的东西,国内不一定能成功,大家可

GordonWei 5269

骚操作,尝试使用Xilinx XVC协议,通过Jlink来下载调试Xilink zynq FPGA芯片

最近一直在玩zynq芯片,手头使用的Xilinx Platform USB Cable 下载线真是辣鸡,速度慢如蜗牛,每次下载bit文件或者烧写flash文件都要大半天,实在是难以忍受。逻辑分析仪看了下xilinx的下载线,速度只有6.25M,并且数据间隔非常大,不懂这线的开发者咋想的,这总线利用率真是低到爆了 上图为xilinx DLC 10下载线波形,惨不忍睹! 为了不浪费生命在下载等待时间上,我打算找找看有没有别的仿真调试选择。经过一番查找后发现Xilinx的仿真器好像选择不是很多,要么贵死要

听我瞎扯淡的博客 1万+

S7-1200与KINCO伺服通信实战:CM CANopen模块配置避坑指南(附完整PDO映射表)

本文详细解析了西门子S7-1200 PLC通过CM CANopen模块与KINCO伺服驱动器的通信配置全流程,重点解决PDO映射混乱、心跳报文配置错误等常见问题。提供硬件组态、参数设置、PDO映射模板及故障排查方案,助力工业自动化系统实现稳定高效的多轴运动控制。

2y3u4i5o6p的博客 1108

TDDFT计算软件Octopus学习笔记(二):基态计算(Si)

本文以硅为例,来进行基态计算。

陈啸的博客 7312

利用 RSAU_LOG_API 把 SAP 安全审核日志接入企业 SIEM 的完整指南

在 SAP 世界里,安全审核日志(Security Audit Log,简称 SAL)是审计和合规的核心基础设施之一。系统会在后台把安全相关的关键事件记录下来,比如:(用户登录与登录失败用户锁定、解锁权限对象或角色变更远程调用(RFC)相关活动关键事务码的启动程序直接执行、批处理作业相关的敏感操作传统 ABAP 系统里,这些日志会写到本地应用服务器上的审计文件中(背后对应类似表RSAUENTR2的结构),包含事件标识、客户端、用户、终端、事务码、时间戳等信息。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 167

Vue和Vue-Element-Admin(六):集成中的CORS(跨域资源共享)问题

在vue-element-admin登录集成时候碰到跨域资源共享问题,CORS(Cross-origin resource sharing)是浏览器的技术规范,浏览器可以发起跨域请求但Javascript脚本不能,传统的ajax只能获取在同域名下的资源,但Html5允许ajax发起跨域请求,解决方案有:JSONP、Flash、IFrame、CORS。 一、CORS(跨域资源共享)问题 针对vue-element-admin的登录模块的后端接口完成后,前端调用时候出现报错,因为前端的端口是9527而后.

叶子叶来 9623

python基于pingouin统计分析:rm_corr计算两个变量之间的重复测量相关性(Repeated measures correlation、plot_rm_corr函数可视化重复测量相关性图

python基于pingouin包进行统计分析:使用rm_corr函数计算两个变量之间的重复测量相关性(Repeated measures correlation)、plot_rm_corr函数可视化重复测量相关性图

statistics+insight+vista+power 687

【AutoCAD中实现双击文本编辑功能】

例如:以下是官方博客例子浅析先加入相关的头文件和库文件。在AutoCAD中有一个很重要的功能,就是双击图形尺寸或文本后会出现一个文本编辑框,用户可在该编辑框中修改文字。本文介绍了如何使用AcEdInplaceTextEditor来实现该功能。实现cad的消息监听。创建一个消息监听的类并在cad中注册来实现消息监听。主要是监听键盘输入。提示:以下是本篇文章正文内容,下面案例可供参考提示:这里对文章进行总结:例如:以上就是今天要讲的内容,本文仅仅简单介绍了的函数和方法。

我的博客 1150

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: P2P 技术如何降低实时视频直播带宽
下一篇: 理解即时通讯WebSocket的通信原理、协议格式、安全性
wecloud1314
博客等级 码龄6年 2493粉丝 649原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值