-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.coffee
More file actions
44 lines (35 loc) · 1.17 KB
/
Copy pathserver.coffee
File metadata and controls
44 lines (35 loc) · 1.17 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
32
33
34
35
36
37
38
39
40
41
42
43
44
app = require('express')()
server = require('http').createServer(app)
io = require('socket.io')(server)
winston = require('winston')
Server = require('./src/Server.coffee').Server
Client = require('./src/Client.coffee').Client
winston.remove(winston.transports.Console);
winston.add(winston.transports.File, {filename: 'logs/server.log', level: 'info'})
winston.add(winston.transports.Console, {level: 'verbose'});
ip = process.argv[2]
if !ip?
winston.error 'Usage: coffee server.coffee brokerIP'
process.exit 1
myServer = new Server(ip, server)
clients = []
sockets = []
app.get('/', (req, res) =>
client = new Client(server, myServer, req.query.client, req.query.target)
clients.push(client)
winston.verbose('Serving index.html to a client')
res.sendFile("#{__dirname}/public/index.html")
)
io.on('connection', (socket) =>
winston.info('Connected to a client over a socket')
sockets.push(socket)
)
server.listen(80, =>
winston.info('HTTP server started')
)
setInterval(( =>
if sockets.length == 0 or clients.length == 0
return
clients[clients.length-1].addSocket(sockets[sockets.length-1])
sockets.pop()
), 100)