const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
  cors: {
    origin: '*',
  }
  // config
});

io.on("connection", (socket) => {
    // Handle data received from the client
    socket.on('data', (data) => {
        console.log('Received:', data.toString());
    });

    socket.on('message', (data) => {
        console.log('Received:', data.toString());
    });

    // Handle when the client disconnects
    socket.on('end', () => {
        console.log('Client disconnected');
    });
});

const port = process.env.PORT || 3000;
const host = '0.0.0.0';
httpServer.listen(port, host, () => {
  console.log(`Server running on port ${host}:${port}`);
});
