码迷,mamicode.com
首页 > 其他好文 > 详细

socket方法

时间:2016-11-28 23:07:08      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:ons   ...   listen   open   websocket   2.7   send   var   received   

// 创建一个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方法

标签:ons   ...   listen   open   websocket   2.7   send   var   received   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!