sockjs

Which websocket library to use with Node.js? [closed]

断了今生、忘了曾经 提交于 2019-11-26 10:56:47
Currently there is a plethora of websocket libraries for node.js, the most popular seem to be: https://github.com/Worlize/WebSocket-Node https://github.com/einaros/ws https://github.com/LearnBoost/engine.io https://github.com/learnboost/socket.io https://github.com/sockjs However I can't find any solid concrete comparisons between any of them... Apparently Socket.io was awesome, but has become quite dated and has failing builds. Both ws and websocket-node claim they are the fastest. And engine.io seems new, but a lot heavier than the lighter aletarntives. It would be amazing if we or someone

WebSocket with Sockjs & Spring 4 but without Stomp

假如想象 提交于 2019-11-26 10:12:49
问题 Is there a way to use WebSockets with SockJS client and Spring 4 server but not using STOMP? Based on this tutorial from Spring\'s website, I know how to set up a WebSocket based application using Stomp and Spring 4. On the client side, we have: var socket = new SockJS(\'/hello\'); stompClient = Stomp.over(socket); stompClient.connect({}, function(frame) { setConnected(true); console.log(\'Connected: \' + frame); stompClient.subscribe(\'/topic/greetings\', function(greeting){ showGreeting

Spring Boot整合WebSocket及Spring Security实例

只愿长相守 提交于 2019-11-26 00:54:02
一.为什么需要WebSocket 在HTTP协议中,所有请求都是由客户端发起的,由服务端进行响应,服务端无法向客户推送消息,但是在一些需要即时通信的应用中,有不可避免的需要服务端向客户端推送消息,传统的解决方案有如下几种 1.轮询 轮询是最简单的解决方案,其意义在于,客户端在固定的时间间隔下不停地向服务端发送请求,查看服务端是否有新的数据,若服务端有新的数据,则返回给客户端,若是服务端没有新的数据,则返回一个空的JSON或者XML文档,轮询对于开发者来说实现方便,但弊端明显:客户端每次都要建立新的HTTP请求,服务端要处理大量的无效请求,在高并发的情景下会严重拖慢服务端的运行效率,同时服务端的资源被极大地浪费了,因此,此种方式并不可取 2.长轮询 长轮询对于轮询存在的问题做了部分解决,在长轮询中,在服务端接收到客户端的请求后不会立即去响应客户端,而是会等到服务端有新的数据时才会立即响应客户端的请求,否则服务端会持有这个请求而不返回,直到有新数据时才返回,这种方式在一定程度上节省了服务端的资源,但是也存在一些问题,例如: (1)如果浏览器在服务响应之前有新的数据要发送就只能创建一个新的并发请求,或者尝试先断掉当前请求,在创建新的请求 (2)TCP和HTTP规范中都有连接超时一说,所以所谓的长轮询并不能一直持续,服务端和客户端的连接需要定期的连接和关闭,这就增大了开发者的工作量