Server data transfer

Started by
4 comments, last by Kylotan 16 years, 6 months ago
Hi, I am developing my server at present, and am subdividing it into smaller applications, some written in C++, some in Python. These apps can be on one machine or many depending on load. They consist of a gateway (accepting connections and managing user data), a master (tracking players and performing zoning), chat, messages, and of course multiple zone servers. Is the best way to transfer data between the app through simple strings, or should I look towards things like python pickling, and boost::python to unpickle in c++? I am sure this is not uncommon, perhaps people could advise? Many thanks Simon
Advertisement
Surely it depends on what data you need to send? The 2 criteria will be complexity of serialisation and need for performance. Pickled Python objects won't be an intrinsically very fast way of sending an object, but it might still be better than an unoptimised method of transforming an object into a string and back again. It'll certainly have fewer bugs.

Generally speaking, I always mandate going for the simplest way first, and changing later if you need. If the data is easy to represent as a string, then just send a string. If it's easier to send as a Python object, then do that instead. Just never assume you will be able to get away with only one or the other because there's rarely a 'one size fits all' solution.
depends on the game kind of. Using binary writing and reading is very easy to use and understand however. Does python have anything like that built in? Like an object that allows data types to be written to a byte buffer? Then if you don't care much you can just give all the objects a serialize function for the time being and optimize later.
Python has built-in serialization -- that's that "pickling" is. The draw-back is that it's hard to unpack a pickled object to another language.
enum Bool { True, False, FileNotFound };
Thanks for the thoughts,

I like the 'start simple' approach. I should probably apply that to more areas of the project! :)

I suppose at least with strings its relatively easy to translate values into hex during packing, shrinking the data....

Back when I had a C++ server, I could just have a base class CMsg, which all Network messages were derived from, then I could just cast messages:

class CPositionUpdate : public CMsg{... }CMsg* newMsg = GetNextMessageFromRxQueue();if ( newMsg->id == POSITION_UPDATE )    CPositionUpdate* posUpdate = (CPositionUpdate*)newMsg;
Wait, wait... what do you mean, "translate values into hex"... hex is a counting system, not a data type. Strings typically need no conversion for network transmission - in fact, they are probably the closest thing to a network's native type as you're going to get, consisting of a stream of bytes. If you want to send integers across the network, you can send them as a string (eg. "100") but you don't need any conversion. And if you are going to send them in binary, then that isn't really using a string, even if it does involve casting to a (char*) at some stage.

This topic is closed to new replies.

Advertisement