猫言猫语

严以律己·宽以待人·自强不息·知行合一

JavaScript WebSocket Client Demo

| JavaScript WebSocket Client Demo已关闭评论

纯 Demo 代码,和当年 XMLHttpRequest 似的,裸调 WebSocket:

var socket = new WebSocket('ws://localhost:9501');
socket.onopen = function(event) {
    socket.send('HelloWorld!');
    socket.onmessage = function(event) {
        console.log('Client received a message', event);
    };
    socket.onclose = function(event) {
        console.log('Client notified socket has closed', event);
    };
    //socket.close();
};

评论已关闭。