懂SockJS(websocket)和Spring4的人请进

qlampskyface 2014-08-15 05:03:06
话说SockJS对于每个domain只能创建一个对象,那就是说,在整个应用中,客户端浏览器对于单一domain只拥有一个SockJS的对象,意味着整个应用中只有一行全局变量
var socket = new SockJS("url");

对于这个要求,怎么才能达到??You know,即使只有一个js中有这行代码,但是html,jsp这些文件中每个文件里面都会引用这个js,那么最终还不是有多少个html或者jsp被访问,就有多少个SockJS对象被创建吗?
...全文
1308 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyan966 2016-12-27
  • 打赏
  • 举报
回复
websocket_multiplex.js 库配合sockjs,可以实现多个websocket channel。
three 2014-10-11
  • 打赏
  • 举报
回复
function SockJsCreator(url) { window.sockjs = window.sockjs || {}; if(!window.sockjs[url]) { window.sockjs[url] = new SockJS("url"); } return window.sockjs[url]; } 这样每次每次得到SockJs都用这个create函数
qlampskyface 2014-08-18
  • 打赏
  • 举报
回复
周末没人回复,自己顶一下
qlampskyface 2014-08-15
  • 打赏
  • 举报
回复
所以问题归结到最后就是,如何保证一个javascript对象在一个客户端始终保持最多只有一个,始终不增加???
qlampskyface 2014-08-15
  • 打赏
  • 举报
回复
具体原因看下面的描述 https://github.com/sockjs/sockjs-client Although the 'SockJS' object tries to emulate the 'WebSocket' behaviour, it's impossible to support all features. One of the important SockJS limitations is the fact that you're not allowed to open more than one SockJS connection to a single domain at a time. This limitation is caused by a in-browser limit of outgoing connections - usually browsers don't allow opening more than two outgoing connections to a single domain. Single SockJS session requires those two connections - one for downloading data, the other for sending messages. Opening a second SockJS session at the same time would most probably block and can result in both sessions timing out.

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧