[JS]A demo of websockets on javascript

2017-11-6 写技术

    ws = new WebSocket("ws:192.168.0.100:4444");
    ws.onopen = function(e) {
        console.log("Connected");
	ws.send("Hello nicholas server!");
    };
    ws.onclose = function(e) {
        console.log("Disconnected: " + e.reason);
    };
    ws.onerror = function(e) {
        console.log("Error ");
    };
    ws.onmessage = function(e) {
        console.log("Message received: " + e.data);
        ws.close();
    };

标签: JS

发表评论:

Powered by anycle 湘ICP备15001973号-1