Last active
February 29, 2016 07:43
-
-
Save ajdeguzman/af90a4cc65629bb810e4 to your computer and use it in GitHub Desktop.
Socket IO Android Chat App Server Code
This file contains 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
/** | |
* 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