首页 > 其他 > 详细

socket方法

时间:2016-11-28 23:04:26      阅读:410      评论:0      收藏:0      [点我收藏+]

// 创建一个Socket实例
var socket = new WebSocket(‘ws://192.168.2.72:8430‘);

// 打开Socket
socket.onopen = function (event) {
//username,msg

// 发送一个初始化消息
socket.send(‘I am the client and I\‘m listening!‘);

// 监听消息
socket.onmessage = function (event) {
console.log(‘Client received a message‘, event);
};

// 监听Socket的关闭
socket.onclose = function (event) {
console.log(‘Client notified socket has closed‘, event);
};

// 关闭Socket....
//socket.close()
};

socket方法

原文:http://www.cnblogs.com/leijuan/p/6111610.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!