Available Game network protocol definition languag

2019-03-09 13:31发布

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.

9条回答
The star\"
2楼-- · 2019-03-09 13:32

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.

查看更多
别忘想泡老子
3楼-- · 2019-03-09 13:33

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?

查看更多
叼着烟拽天下
4楼-- · 2019-03-09 13:40

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.

查看更多
来,给爷笑一个
5楼-- · 2019-03-09 13:44
干净又极端
6楼-- · 2019-03-09 13:45

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.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-03-09 13:46

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..

查看更多
登录 后发表回答