oyun / server.js
Eren Ensarioğlu
Create server.js
d6524f8 verified
Raw History Blame Contribute Delete
599 Bytes
const express = require('express');
const { WebSocketServer } = require('ws');
const path = require('path');
const app = express();
const PORT = 7860;
app.use(express.static(path.join(__dirname, 'public')));
const server = app.listen(PORT, () => {
console.log('Oyun sunucusu hazır!');
});
const wss = new WebSocketServer({ server });
wss.on('connection', (ws) => {
ws.on('message', (data) => {
wss.clients.forEach((client) => {
if (client !== ws && client.readyState === ws.OPEN) {
client.send(data.toString());
}
});
});
});