mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
24 lines
677 B
TypeScript
24 lines
677 B
TypeScript
import io = require('socket.io');
|
|
|
|
var socketManager = io.listen(80);
|
|
|
|
socketManager.sockets.on('connection', socket => {
|
|
socket.emit('news', { hello: 'world' });
|
|
socket.on('my other event', data => {
|
|
console.log(data);
|
|
});
|
|
});
|
|
|
|
// Storing data Associated to a client.
|
|
// Server side sample
|
|
io.listen(80).sockets.on('connection', function (socket) {
|
|
socket.on('set nickname', function (name) {
|
|
socket.set('nickname', name, function () { socket.emit('ready'); });
|
|
});
|
|
|
|
socket.on('msg', function () {
|
|
socket.get('nickname', function (err, name) {
|
|
console.log('Chat message by ', name);
|
|
});
|
|
});
|
|
}); |