-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (27 loc) · 895 Bytes
/
server.js
File metadata and controls
35 lines (27 loc) · 895 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
var http = require('http')
var fs = require('fs')
var WebSocketServer = require('websocket').server
var WebSocketTimer = require('./webSocketTimer.js')
var server = http.createServer(function(req, res){
fs.readFile('./client.html',null, function(err, data){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data)
})
})
var wsServer= new WebSocketServer({
httpServer: server
})
wsServer.on('request', function(request){
var connection= request.accept(null, request.origin) || null
var timer = new WebSocketTimer({stopTime:10,
endFunc:function(){
this.webSocket.send( JSON.stringify({status:'that\'s all'}) )
} })
timer.addWebSocket(connection)
//start the timer as soon as the connection is established
timer.start()
connection.on('close', function(connection){
console.log('good bye')
})
})
server.listen(3000)