1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2024-11-17 01:16:33 +00:00
tic-tac-toe-ws/server.mts
2024-09-02 22:35:04 +02:00

19 lines
494 B
TypeScript

import { WebSocketServer } from "ws";
const port = 1234
const wss = new WebSocketServer({ port });
console.log(`waiting for connection on ws://localhost:${port}`);
wss.on("connection", (ws, req) => {
console.log(`${req.socket.remoteAddress} connected`);
ws.addEventListener("message", (event: any) => {
//const message = JSON.parse(event.data.toString());
const message = event.data.toString();
console.log(`message from client : ${message}`);
});
});