Last active
March 14, 2016 18:12
-
-
Save diem1/c82f4975cdaf4cea323b to your computer and use it in GitHub Desktop.
NodeJS_Socket.io_client-server
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
<meta charset="utf-8"> | |
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> | |
<script> | |
var socket = io.connect('ws://localhost:3333'); | |
socket.on('news', function (data) { | |
console.log(data); | |
socket.emit('my other event', { my: 'data' }); | |
}); | |
</script> |
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
// server | |
var io = require('socket.io').listen(3333); | |
var http = require('http'); | |
var ss = require('socket.io-stream'); | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); | |
socket.on('my other event', function (data) { | |
console.log(data); | |
}); | |
socket.on('disconnect', function () { | |
console.log('user disconnected'); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment