// 创建一个Socket实例bai
var socket = new WebSocket(‘ws://localhost:8080’);
// 打开Socket
socket.onopen = function(event) {
// 发送一du个初始化消息
socket.send(‘I am the client and I’m listening!’);
// 监听消息
socket.onmessage = function(event) {
console.log(‘Client received a message’,event);
};
// 监听Socket的关闭zhi
socket.onclose = function(event) {
console.log(‘Client notified socket has closed’,event);
};
// 关闭Socket…
//socket.close()
};
js监听TCP连接
最新推荐文章于 2024-06-21 09:39:25 发布