views:

1989

answers:

10

I've been looking for a good general purpose binary network protocol definition framework to provide a way to write real-time game servers and clients (think World Of Warcraft or Quake III) in multiple languages (e.g. Java backend server and iPhone front-end client written in Objective-C and Cocoa).

I want to support Java Flash clients, iPhone clients and C# clients on windows (and XNA clients on XBOX).

I'm looking for a way to efficiently send/receive messages over a TCP/IP or UDP socket stream connection. I'm not looking for something that can be sent over an HTTP Web Service, like JSON or XML marshalled Objects. Although Hessian's binary web service protocol is a very interesting solution

I want a network protocol format and client/server basic implementation that will allow a client to connect to a server and send any message in the defined protocol and receive any message in the protocol without having to bind to some kind of RPC endpoint. I want a generic stream of any message in my protocol incoming and outgoing. This is so that I can support things like the server sending all clients the positions of various entities in the game every 100 milliseconds.

A: 

I want to echo Bill K's suggestion. It's not hard to roll your own protocol.

For the iPhone side, have a look at AsyncSocket which support for delimiter based TCP packets built in, and it's not hard to build a solution which uses packet headers.

If you quickly want to have a testserver to play against AsyncSocket on the iPhone, you can look at Naga (for the java server part) which has ready made stuff both for delimiter based packets and packets with headers. Naga was partially written with networked games in mind.

Nuoji
A: 

I disagree with "roll your with simple delimited strings approach": question is, what exactly would be the benefit? Getting to write and maintain more code? The only reasons I could see would be lack of tool support (writing for some odd platform), or specific (very) hard performance or message size constraints. Or, sometimes, really wanting to write a format -- that's ok, but it must be an explicit reason.

Depending on exact needs I would suggest considering JSON, since it can read and write arbitrary messages; has good object binders for Java (just like xml), is easier to read than binary formats, and is all around "good enough" for many use cases.

If message size is very important, Protobuf can work well -- while its size is not always as small as gzipped alternatives (gzip+xml, gzip+json compress very well), it's usually close.

StaxMan
@StaxMan, I completely agree that writing your own custom protocol is a waste of time and just creates a maintenance nightmare when trying to support multiple languages or extending it.JSON and gzip+json might be a decent option, especially for writing a web service but I'm thinking more about situations where I don't need or want a text based format (like a web service), but in situations where you'd want fast binary message protocol like building a game server (like World of Warcraft or Quake III), in those cases the text parsing of JSON to a native object/struct would be prohibitive.
Dougnukem
A: 

ASN.1 fits the definition of "good general purpose binary network protocol definition framework". It's also standardized by ITU-T, so there's a lot of existing tools and libraries for various languages.

The DER encoding is suitable for efficient network communications, the XER encoding for human-readable (and writable) permanent storage.

Christoffer
+10  A: 

The network protocol frameworks I've found are as follows:

  1. Google's Protocol Buffer - but it lacks support for things like sending/receiving arbitrary messages from your given protocol.
  2. Apache Thrift - an interesting option but it is geared mainly towards RPC instead of generic game client/server socket type connections where the client or server can send messages at any time and not just in response to a client RPC request.
  3. Raknet Multiplayer - Raknet provides full multiplayer network library (it's free for indie development with revenue under $250k)
  4. Hessian Binary Web Service Protocol - is a HTTP web service binary protocol, it is well-suited to sending binary data without any need to extend the protocol with attachments.

Raknet provides a good game/simulation oriented multiplayer library.

Apache Thrift and Google's protocol buffers seem to be the simplest approaches to using in a game network protocol client/server architecture.

Hessian seems like a great fit if you want to create a web based game server with a Java or flash client using some type of server push technology like COMET. Hessian might provide a really interesting way to support real-time games on the web and even be able to host them on VM web solutions like Google's App engine or Amazon's EC2.

There's some discussion about using various protocol definition frameworks for games and other uses:

Dougnukem
Personally I'd look at Protocol Buffers first as there seems to be support for quite a few languages now. You're don't require you to use RPC to send ProtoBufs, so you could easily stream them over a socket as long as you specify the length first (e.g length|protobuf|length|protobuf...). The only downside is that all messages have to be defined a head of time, which is probably a good thing.
mattkemp
A: 

Because you want to use different languages and also because you want something clean/small, I suggest the protocol buffers of google. You need a pre-compile part for the RPC but I really think that's the best option when you begin to mix different languages.. Here's the link: http://code.google.com/apis/protocolbuffers/docs/overview.html

A: 

Why not implement UDP directly? Your question mostly mentions what you don't want.. What further form of abstration do you want on top of UDP? Download the Quake III sourcecode and see how they frame game updates over UDP?

The IP protocol has been designed to support multiple devices/OSes in a uniform way, isn't this what you ask for? What protocol has implementations across a huge range of systems, hmm, IP perhaps?

Tungano
The protocol I'm discussing is not exactly the same low-level transport protocol that UDP or TCP implements. I'm talking about the application level protocol.From what I read about the Quake III network model (http://www.tilion.org.uk/Games/Quake_3/Network_Protocol), they implement a very simple subset of game commands to be sent to each client. The code to receive those messages over the network is written in the C client/server, I'm looking for a way to automate that code generation so I can create client/servers in other languages like Java/Objective-c using the same application protocol.
Dougnukem
+1  A: 

If you do go the route of writing your own protocol, you may want to read the answer I posted here.

In summary it discusses what you should think about when writing a protocol, and list a few tricks for versioning and maintaining backwards and forward compatibility.

grieve
A: 

Some time ago, I asked a pretty much related question here on SO, that you may want to check out for further pointers: Tools for experimental Protocol design/development?

none
A: 

DIS

OJW
A: 

If you are really concerned about multiple platforms and language, be sure to take into account endian issues. A binary protocol designed for this use must use network-byte-order, so it needs custom per-data-type serialization functions; you cannot just blindly push C structs into network buffers.

A common solution for this problem at game companies is to have protocol description language or specification in a simple format like XML or python or lua, and then have code generation for each target language that generated packet classes with both data structure and serialization. This specification could use a type system that starts with basic types, then extends to include game-specific types with semantic information, enumerations or more complex structures. For example a data file could look like:

Attack = {
  source = 'objectId',
  target = 'objectId',
  weapon = 'weapon::WEAP_MAIN',
  seed = 'int'
}

This could generate code like:

#define PT_ATTACK 10002

class PacketAttack : public Packet {
  public:
    PacketAttack () : m_packetType(PacketAttack::s_packetType) {}

    ObjectId m_source;
    ObjectId m_target;
    WeaponType m_weapon;
    int m_seed;

   bool Write(Stream* outStream) {
       Packet::Write(outStream);
       outStream << m_source;
       outStream << m_target;
       outStream << m_weapon
       outStream << m_seed;
   }

   bool Read(Stream* inStream);

 static const int s_packetType;
};

This does require some more infrastructure.. streams, packet base classes, safe serialization functions..

sean riley