热门关键字:
jquery > jquery教程 > html5 > html5创建websocket对象的通用方法

html5创建websocket对象的通用方法

1947
作者:管理员
发布时间:2015/10/10 15:52:10
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=723

html5创建websocket对象的通用方法

html5创建websocket对象的通用方法

var ws = null;
var url = null;
var urlPath = "/msg";
var urlJs = "/sockjs/msg";
var transports = [];

if (window.location.protocol == 'http:') {
	url = 'ws://' + window.location.host + urlPath;
} else {
	url = 'wss://' + window.location.host + urlPath;
}
if ('WebSocket' in window) {
	ws = new WebSocket(url);
} else if ('MozWebSocket' in window) {
	ws = new MozWebSocket(url);
} else {
	ws = new SockJS(urlJs, undefined, {protocols_whitelist : transports});
}

ws.onopen = function() {
	log('Socket 连接打开,请稍候...');
};
ws.onmessage = function(event) {
	
};
ws.onclose = function(event) {
	log('Socket 连接已关闭');
};





如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:html5 websocket
友荐云推荐