Last active
July 13, 2016 18:38
-
-
Save beefy/9c7044fcc7bb03e2392f72deb314cf19 to your computer and use it in GitHub Desktop.
A simple nodejs/socket.io chat
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 socket = require('socket.io-client')('http://127.0.0.1:3000'); | |
socket.on('connect', function(){}); | |
socket.on('event', function(data){}); | |
socket.on('disconnect', function(){}); | |
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
rl.on('line', function(line){ | |
socket.emit('chat message',line); | |
}) |
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 app = require('express')(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
io.on('connection', function(socket){ | |
console.log('a user connected'); | |
socket.on('disconnect',function(){ | |
console.log('user disconnected'); | |
}); | |
}); | |
io.on('connection', function(socket){ | |
socket.on('chat message', function(msg){ | |
console.log('message: ' + msg); | |
}); | |
}); | |
http.listen(3000, function(){ | |
console.log('listening on *:3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment