Skip to content

Commit

Permalink
Create app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bwcho75 committed Apr 16, 2014
1 parent 0fc721b commit abe1dd5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions socket_io_chatting_sendToAllOnly/app.js
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);
})
});

0 comments on commit abe1dd5

Please sign in to comment.