server for my chess game
Diffstat (limited to 'src/index.js')
| -rw-r--r-- | src/index.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/index.js b/src/index.js index 67f473c..53051cf 100644 --- a/src/index.js +++ b/src/index.js @@ -6,11 +6,18 @@ const PORT = process.env.PORT || 3000; const wss = new WebSocket.Server({ port: PORT }) console.log(`Server started on port ${PORT}`) wss.on('connection', ws => { - console.log('connected') - ws.send(gdCom.putVar("a new client has connected")) + + console.log("client connected") + + // on message recieved ws.on('message', (message) => { - let recieveBuff = Buffer.from(message) - let recieve = gdCom.getVar(recieveBuff) - console.log(recieve.value) + console.log("attempting to relay the message") + wss.clients.forEach((client) => { + console.log("relaying message to client") + if (client.readyState === WebSocket.OPEN) { + var recieve= gdCom.getVar(Buffer.from(message)) + console.log(recieve.value) + client.send(gdCom.putVar(recieve)) + }}) }) }) |