code
import * as express from 'express';
import * as http from 'http';
import { WebSocket, WebSocketServer } from 'ws';
const app = express();
const server = http.createServer(app);
const wss = new WebSocketServer({ clientTracking: true, noServer: true });
server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, socket as any, head, function (ws) {
wss.emit('connection', ws, request);
});
});
wss.on('connection', (ws, req) => {
ws.send('Hello');
});
server.listen(8888);