TRANSPORT. This is a module that takes care of reading data from network. Transport is for example TCP or UDP, but it might be also serial or something else. You should have functions in this module to connect, read, write and disconnect.
PROTOCOL. This is a way in which you are parsing data (not your game logic data yet, just whole messages). In example you can have "sign delimeter" protocol, which reads data from transport and creates messages from it by splitting data where "delimeter sign" occurs.
123%456%789%
TRANSPORT. This is a module that takes care of reading data from network. Transport is for example TCP or UDP, but it might be also serial or something else. You should have functions in this module to connect, read, write and disconnect.
PROTOCOL. This is a way in which you are parsing data (not your game logic data yet, just whole messages). In example you can have "sign delimeter" protocol, which reads data from transport and creates messages from it by splitting data where "delimeter sign" occurs.
123%456%789%
this data read from transport would be converted to 3 messages [123,456, 789] if your delimeter is %. Special case of this protocol is "line receiver" where delimeter sign is "\n".
PARSER. Messages that you get from protocol should be parsed. Parsing is based on some type of identifier sent in message. I have separated ID into type and subtype. My ID is 2 bytes long, and I store type id in 4 first bits, and subtype id in rest 12 bits. How to do this you have to read elsewhere. This way your switch (ifs) is more optimized. Store these identifiers at the top of parser module. In example:
TYPE_SYSTEM = 1 SUBTYPE_LOGIN_REQUEST = 1 if type == TYPE_SYSTEM: if subtype == SUBTYPE_LOGIN_REQUEST: do_something()
PARSER. Messages that you get from protocol should be parsed. Parsing is based on some type of identifier sent in message. I have separated ID into type and subtype. My ID is 2 bytes long, and I store type id in 4 first bits, and subtype id in rest 12 bits. How to do this you have to read elsewhere. This way your switch (ifs) is more optimized. Store these identifiers at the top of parser module. In example:
TYPE_SYSTEM = 1
SUBTYPE_LOGIN_REQUEST = 1
if type == TYPE_SYSTEM:
if subtype == SUBTYPE_LOGIN_REQUEST:
do_something()