Counter-Strike-HUD/cs-hud-observer

Data packet concated

Closed this issue · 1 comments

Data arriving from remote game socket usually is concated and forms invalid JSON object, and on parse, it creates an error,
so it looks like a few events are missing, but really they just not being parsed successfully.

Further, inspection showed that the issue was not in the TCP data fragmentation, it was caused by nodejs server.
Error happened in the write method in case of fast data arrival, where node doesn't execute send synchronously.
It fills buffer on that tick and sends string batch.
Obviously, client-side JSON.parse() failed on parsing, so now we use regex to extract all object values from the string and resend them to the client socket.

https://github.com/kallefrombosnia/cs-hud-observer/blob/eb1749169b2bf3c451aeb5a067a48f7b47568813/backend/src/handler/server.ts#L187-L203

Gonna close this issue for now, but I suspect something similar is gonna happen in the future.