Skip to content

Instantly share code, notes, and snippets.

@willard1218
Created October 25, 2017 04:00
Show Gist options
  • Save willard1218/5ce0221c054b482eff98453e2f60b567 to your computer and use it in GitHub Desktop.
Save willard1218/5ce0221c054b482eff98453e2f60b567 to your computer and use it in GitHub Desktop.
web socket
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(data) {
console.log("reveice : " + data)
if (ws.readyState === WebSocket.OPEN) {
//
for ( var i = 0 ; i < 100 ; i ++) {
setTimeout(function() {
ws.send(i);
}, 1000 * i);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment