标签: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()
};
标签:ons ... listen open websocket 2.7 send var received
原文地址:http://www.cnblogs.com/leijuan/p/6111610.html