+ 1
How to add Web sockets in game
2 Respostas
+ 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
+ 2
Thank you so much 😘