-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (31 loc) · 1.01 KB
/
app.js
File metadata and controls
31 lines (31 loc) · 1.01 KB
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
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
fs = require('fs');
app.listen(3000);
function handler(req, res) {
fs.readFile(__dirname + '/index.html', function(err, data) {
if (err) {
res.writeHead(500);
return res.end('Error');
}
res.writeHead(200);
res.write(data);
res.end();
})
}
io.sockets.on('connection', function(socket) {
socket.on('emit_from_client', function(data) {
//console.log(data);
//接続しているソケットのみ
//socket.emit('emit_from_client', 'hello from server: ' + data);
//接続しているソケット以外全部
//socket.broadcast.emit('emit_from_client', 'hello from server: ' + data);
socket.client_name = data.name;
var client_name = socket.client_name;
//socket.get('client_name', function(err, name) {
io.sockets.emit('emit_from_server', '[' + client_name + '] : ' + data.msg);
//});
//接続しているソケット全部
//io.sockets.emit('emit_from_client', '[' + socket.id + '] : ' + data);
});
});