'Prevent socket.io spamming sockets
I am making a multiplayer game using socket.io. Here is a part of my server code.
io.on('connection', (socket) => {
console.log("socket has connected!!")
socket.on("go", (name) => {
addPlayer(name);
})
socket.on("move", (angle) => {
//do movement stuff
})
})
Now people are crashing my server by creating spam sockets. They are opening console and typing this code in client:
setInterval(() => {
var socket = io()
socket.emit("go", "haha ugothacked")
},10)
This creates 100 players each second and eventually crashes my server. How do I prevent this. I know you have to use some kind of rate limit. I don't know how to get ip of the socket.
I am using socket.io v4
How do I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|