+ 1

How to add Web sockets in game

25th Oct 2021, 9:35 AM
Abhijeet Sahu
Abhijeet Sahu - avatar
3 Réponses
+ 3
What You Want The Web Sockets To Do? A Simple Method (Server): const WebSocket = require('ws'); const sock = new WebSocket.Server({port:8080}); sock.on('connection', socket => { socket.send('Connected!') console.log('New User Connected!') }); A Simple Method (Client): const WebSocket = require('ws'); const socket = new WebSocket('ws://localhost:8080') socket.on('message', msg => { console.log(msg.toString()) }); Also, Don't Forget To Install ws Before Using This Code! Install Using: npm i ws
25th Oct 2021, 10:21 AM
Sancho Godinho
Sancho Godinho - avatar
+ 2
Thank you so much 😘
25th Oct 2021, 2:55 PM
Abhijeet Sahu
Abhijeet Sahu - avatar