-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (30 loc) · 953 Bytes
/
server.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
var express = require('express');
var app = express();
const open = require('open');
var path = require('path')
app.use(express.static('front/'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/front/index.html'));
});
app.listen(3000, function () {
console.log('Simulator running on port 3000');
});
open('http://localhost:3000');
var WebSocketServer = require("ws").Server;
var ws = new WebSocketServer({ port: 8100 });
console.log("Server started...");
ws.on('connection', function (ws) {
console.log("Browser connected online...")
ws.on("message", function (str) {
var ob = JSON.parse(str);
switch (ob.type) {
case 'text':
console.log("Received: " + ob.content)
ws.send('{ "type":"text", "content":"ServerReady"}')
break;
}
})
ws.on("close", function () {
console.log("Browser gone.")
})
});