Created
October 17, 2016 20:23
-
-
Save rectangletangle/3ad486daa8db3cd43719031840776caf to your computer and use it in GitHub Desktop.
This file contains 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 characters
// 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." | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment