1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2024-09-29 06:06:37 +00:00
tic-tac-toe-ws/server.mts

19 lines
494 B
TypeScript
Raw Normal View History

2024-09-02 20:34:24 +00:00
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}`);
});
});