-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (28 loc) · 885 Bytes
/
index.js
File metadata and controls
40 lines (28 loc) · 885 Bytes
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
38
39
40
var express = require('express');
var app = express();
var path = require('path');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
app.use(express.static(path.join(__dirname, 'app')));
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, '/app/.index.html'));
console.log('requ');
});
//Handle socket connections from client
io.on('connection', function(client){
console.log("client connected");
client.emit('msg','Welcome');
//Handle msgs from client
client.on('client-msg', function(data){
console.log(data);
//Broadcast to connected clients
client.broadcast.emit('msg', client.nickname + " : " + data);
//send msg to sender too
client.emit('msg', client.nickname + " : " + data);
});
//Listen for join event
client.on('join', function(name){
client.nickname = name;
});
});
server.listen(8080);