-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (33 loc) · 951 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Server part
var connect = require('connect');
console.log(__dirname);
console.log(process.cwd());
var app = connect.createServer(
connect.static(process.cwd())
).listen(80);
console.log('Start server on port : '+80);
/*
// Define socket part
var io = require('socket.io');
var wsServer = io.listen(app);
wsServer.sockets.on('connection', function(socket) {
console.log('### connection');
socket.on('message', function(message) {
console.log('### message: '+message);
socket.broadcast.emit('message', message);
});
});
*/
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
wss.broadcast(message);
});
//ws.send('something');
});
wss.broadcast = function(data) {
for(var i in this.clients)
this.clients[i].send(data);
};