Sign in to follow this  

Server data transfer

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this