-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (46 loc) · 1.31 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var express = require('express')
, http = require('http')
, path = require('path')
var app = express();
var clients = {};
// all environments
app.set('port', process.env.PORT || 3008);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser({uploadDir:'c:\\tmp'}));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req,res){
res.render('gomoku',{
});
});
var client={};
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.sockets.on('connection',function(socket){
socket.on('online',function(data){
client[data.from]={
socket:socket.id
}
console.log(data.from);
console.log(client[data.from].socket);
});
//有人查看历史记录
socket.on('move',function(data){
console.log(data.move);
if(client[data.to]){
console.log(client[data.to].socket);
io.sockets.socket(client[data.to].socket).emit('move',{from:data.from,to:data.to,move:data.move});
}
});
//掉线,断开链接处理
socket.on('disconnect',function(){
});
});
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});