Problems with TCP



Problems with TCP framing

I was seeing a lot of deserialization and mis-interpreted messages in my proxy and game server communication channel today. I think I found the issue to be related to the fact that I lost message framing when I migrated away from Mangos.

Interestingly, websockets provides framing for me, so I don’t really see these issues creep up in those connections.

The issue also shows itself more when I have a lot of clients connected to the proxy (presumably the messages between the proxy and server start getting packed together which messes things up)

Found this nice article on the topic

There are three approaches listed:

  1. Variable length identifiers in the messages
  2. Delimiter variables between messages
  3. Fixed length messages (ie every message is the same length)

This is only for server to proxy communications. I think I’ll probably do the variable length identifiers. I guess I can just prepend the byte stream with the length and then ensure I read the whole thing before sending it to the deserializer.

I ended up deciding to use a premade package called goframe. Mostly because its small, simple, and did exactly what I wanted.