Created
October 17, 2016 20:23
Revisions
-
rectangletangle created this gist
Oct 17, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ // Note that the path doesn't matter for routing; any WebSocket // connection gets bumped over to WebSocket consumers socket = new WebSocket("ws://127.0.0.1:7000/chat/"); socket.onmessage = function(e) { alert(e.data); } socket.onopen = function() { socket.send("hello world"); } // Call onopen directly if socket is already open if (socket.readyState == WebSocket.OPEN) socket.onopen(); //Socket.io var socket = io.connect(); // React to a received message socket.on('ping', function (data) { // Modify the DOM to show the message document.getElementById("msg").innerHTML = data.msg; // Send a message back to the server socket.emit('pong', { msg: "The web browser also knows socket.io." }); });