-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('express'); | ||
var routes = require('./routes'); | ||
var http = require('http'); | ||
var path = require('path'); | ||
|
||
var app = express(); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
var httpServer =http.createServer(app).listen(8080, function(req,res){ | ||
console.log('Socket IO server has been started'); | ||
}); | ||
// upgrade http server to socket.io server | ||
var io = require('socket.io').listen(httpServer); | ||
|
||
io.sockets.on('connection',function(socket){ | ||
socket.emit('toclient',{msg:'Welcome !'}); | ||
socket.on('fromclient',function(data){ | ||
socket.broadcast.emit('toclient',data); // 자신을 제외하고 다른 클라이언트에게 보냄 | ||
socket.emit('toclient',data); // 해당 클라이언트에게만 보냄. 다른 클라이언트에 보낼려면? | ||
console.log('Message from client :'+data.msg); | ||
}) | ||
}); |