forked from codefoster/waterbug-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 1.1 KB
/
Copy pathserver.js
File metadata and controls
32 lines (25 loc) · 1.1 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
/// <reference path="typings/main/ambient/express/index.d.ts" />
var express = require("express");
var app = express();
var server = require("http").Server(app);
var io = require("socket.io").listen(server);
var port = process.env.port || 8080;
io.on("connection", function(socket) {
// wire up a handler for the client sending a 'stroke' message
console.log('connection');
console.log(socket.conn.id);
// these are simple pass thru's
// when any client sends a "stroke" or "startrace" message it will be passed on to all other connected clients
// inside these handlers is where we would "intercept" all messages to persist data to a database
socket.on("stroke", data => io.emit("stroke", data));
socket.on("startrace", data => io.emit("startrace", data));
socket.on("stoprace", data => io.emit("stoprace", data));
});
app.get('/', (req,res) => {
res.header('200','{"Content-Type","text/html"}');
res.send("Socket server active and listening...");
res.end();
});
server.listen(port, function() {
console.log("Listening on port %s...", server.address().port);
});