WebSocket implementation for 93Protocol

This commit is contained in:
heckeralt 2024-08-25 17:42:38 -04:00
parent 4af1d31aa0
commit bb554a6562
1 changed files with 26 additions and 0 deletions

26
ws-server.js Normal file
View File

@ -0,0 +1,26 @@
// Importing the required modules
const WebSocketServer = require('ws');
// Creating a new websocket server
const wss = new WebSocketServer.Server({ port: 8080 })
// Creating connection using websocket
wss.on("connection", ws => {
   console.log("new client connected");
   // sending message to client
   ws.send('Welcome, you are connected!');
   //on message from client
   ws.on("message", data => {
       console.log(`Client has sent us: ${data}`)
   });
ws.on("ip", data = {
console.log(`data of connected user: ${data}`)
});
   // handling what to do when clients disconnects from server
   ws.on("close", () => {
       console.log("the client has connected");
   });
   // handling client connection error
   ws.onerror = function () {
       console.log("Some Error occurred")
   }
});
console.log("The 93Protocol server is running on port 8080");