Skip to content

Instantly share code, notes, and snippets.

@ajdeguzman
Last active February 29, 2016 07:43
Show Gist options
  • Save ajdeguzman/af90a4cc65629bb810e4 to your computer and use it in GitHub Desktop.
Save ajdeguzman/af90a4cc65629bb810e4 to your computer and use it in GitHub Desktop.
Socket IO Android Chat App Server Code
/**
* Created by wogaljohn on 2/29/2016.
*/
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/',function(req,res){
res.sendFile(__dirname+'/index.html');
})
io.on('connection',function(socket){
console.log('one user connected '+socket.id);
socket.on('message',function(data){
/* var sockets = io.sockets.sockets;
sockets.forEach(function(sock){
if(sock.id != socket.id)
{
io.emit('message',data);
}
})*/
io.emit('message',data);
})
socket.on('disconnect',function(){
console.log('one user disconnected '+socket.id);
})
})
http.listen(3000,function(){
console.log('server listening on port 3000');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment