I'm new to Socket.io
I'm programming an online browser game in Node.JS with a chat application
And I want to limit the message size to 1MB and reject if it's bigger than that
This is my code:
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server, { cors: { origin: "*" } });
const PORT = process.env.PORT || 3001;
const cors = require("cors");
// ... some code ...
io.on('connection', (socket) => {
// ... some code ...
socket.on("chat-message", message => {
// I did something like this:
if (message.length > 1000000) return;
});
});
But the server keeps receiving the message even if it's 100MB
I want to reject it before receiving the whole message