-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
31 lines (25 loc) · 735 Bytes
/
Copy pathserver.ts
File metadata and controls
31 lines (25 loc) · 735 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
import * as dotenv from 'dotenv'
dotenv.config()
import { Server } from 'ws'
import { StateMachine } from './src/StateMachine'
import { TurtleC } from './src/TurtleC'
const port = 3000
const wss = new Server({ port })
const machine = new StateMachine()
wss.on('connection', async (ws) => {
console.log('connection!')
const turtle = new TurtleC(ws, machine)
await turtle.init()
// ws.send(
// JSON.stringify({
// type: 'eval',
// fn: 'return turtle.turnLeft()',
// nonce: 1,
// })
// )
// ws.on('message', async (message: string) => {
// console.log('sending: ' + message)
// ws.send('I got: ' + message)
// })
})
console.log('done')