Skip to content

Instantly share code, notes, and snippets.

@koduki
Last active July 18, 2016 18:55
Show Gist options
  • Save koduki/3cbacaaff833621e9126c01cb81ebb0a to your computer and use it in GitHub Desktop.
Save koduki/3cbacaaff833621e9126c01cb81ebb0a to your computer and use it in GitHub Desktop.
$(function(){
var host = "ws://localhost:8888/";
var socket = new WebSocket(host);
socket.onmessage = function(message){
console.log(socket.readyState + " " + message.data);
}
$("#sendBtn").on("click",function(){
message = $("#message").val()
socket.send(message);
});
})
var ws = require("websocket.io");
var server = ws.listen(8888, => console.log("ws start"));
server.on("connection", function(socket) {
socket.on("message", function(data) {
server.clients.forEach((client) => client.send(data));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment