Last active
July 18, 2016 18:55
-
-
Save koduki/3cbacaaff833621e9126c01cb81ebb0a to your computer and use it in GitHub Desktop.
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 characters
$(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); | |
}); | |
}) |
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 characters
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