forked from webber0928/socketDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (32 loc) · 913 Bytes
/
index.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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
console.log('get /');
});
app.get('/mobi', function(req, res){
res.sendFile(__dirname + '/index1.html');
console.log('get /mobi');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
console.log('io.emit='+msg);
});
socket.on('ask_channel', function(msg){
io.emit('ask_channel', msg);
console.log('ask_channel='+msg);
});
socket.on('answer_channel', function(msg){
io.emit('answer_channel', msg);
console.log('answer_channel='+msg);
});
socket.on('linked', function(msg){
io.emit(msg.room, msg);
console.log('linked='+msg.room);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});