first commit
This commit is contained in:
24
src/server.ts
Normal file
24
src/server.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import WebSocket from 'ws';
|
||||
import * as process from "node:process";
|
||||
|
||||
const wss = new WebSocket.Server({ port: process.env.SERVER_PORT });
|
||||
|
||||
console.log(`Server started on port ${process.env.SERVER_PORT}`);
|
||||
|
||||
wss.on('connection', (ws: WebSocket) => {
|
||||
console.log('New client connected');
|
||||
|
||||
ws.on('message', (message: string) => {
|
||||
console.log(`Received message: ${message}`);
|
||||
wss.clients.forEach((client) => {
|
||||
client.send(`Server received your message: ${message}`);
|
||||
});
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
console.log('Client disconnected');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user