-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.coffee
More file actions
32 lines (28 loc) · 899 Bytes
/
server.coffee
File metadata and controls
32 lines (28 loc) · 899 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
# Generated by CoffeeScript 1.6.3
(->
http = require("http")
WebSocketServer = require("ws").Server
url = require("url")
_ = require("underscore")
ip = process.env.OPENSHIFT_NODEJS_IP or "127.0.0.1"
port = process.env.OPENSHIFT_NODEJS_PORT or 8080
server = undefined
http = require("http")
server = http.createServer((request, response) ->
response.writeHead 200,
"Content-Type": "text/plain"
response.write "Hello World"
response.end()
).listen(port, ip)
wss = new WebSocketServer(server: server)
console.log "websocket server created"
wss.on "connection", (ws) ->
id = setInterval(->
ws.send JSON.stringify(new Date()), ->
, 1000)
console.log "websocket connection open"
ws.on "close", ->
console.log "websocket connection close"
clearInterval id
console.log "Server is running at " + ip + ":" + port
).call this