From e4498c56048c44d1dae41d27c3213f94ccb027a8 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Wed, 21 Jul 2021 23:33:04 +0530 Subject: Implemented basic connection between client and server using websockets --- src/server/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/server') diff --git a/src/server/index.js b/src/server/index.js index 2b85ea5..f8b5ca7 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -1,11 +1,19 @@ const express = require('express'); -const path = require('path'); const app = express(); +const http = require('http').Server(app); +const path = require('path'); +const io = require('socket.io')(http); app.use(express.static(path.join(__dirname, '../../build'))); +io.on('connection', (socket) => { + socket.on('update-remote-board', (board) => { + io.emit('update-client-board', board) + }) +}); + // Start the server const PORT = process.env.PORT || 5000; -app.listen(PORT, () => { +http.listen(PORT, () => { console.log(`App listening on port ${PORT}`); }); -- cgit v1.2.3