I am coding a multiplayer game and use a Websocket Server to send messages between clients for the game to work. During random times in the game, there is a massive, absolutely massive delay in the message time between the messages ONLY sent from the server to the client. The delay from the client to the server does not increase during this. This only happens periodically, most of the time the game works fine.
I built a ping meter to measure the time between the client sends a message and the server receives it and vica versa. In the server to client, during random periods, the ping skyrockets. I'm talking like 20+ seconds. It doesn't immediately jump. It increases steadily.
I can't put all the code for the game here(over 10,000 lines), but here is how the game works:
Server send a hostupdate to all sockets connected to the room.
- It's a JSON message. I don't exactly know how big the message size is, but there is a considerable amount of objects (a few hundred).
- Server sends this message every 30 ms. I don't know if I am straining the sockets by sending it too fast? I kind of need a good frame rate sent to players.
- This is the message that is being delayed sent to clients.
Client sends a joinerupdate to server:
- Every 30 ms
- Sends updates like change in x and y
I am using the WS npm module to run my WebSocket Server and using the default browser built in websocket to connect to my server.