NetworkDesign: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
No edit summary
imported>Hendrik Brummermann
Line 34: Line 34:


== Transmitting Messages over TCP ==
== Transmitting Messages over TCP ==
The idea behind arianne's network protocol is to use a single stream of TCP packets between the server and the clients. Different kinds of in-game actions create different types of messages that are then interpreted at the opposite side in to meaningful data.
The idea behind Arianne's network protocol is to use a single TCP stream between the server and the clients. Different kinds of in-game actions create different types of messages that are then interpreted at the opposite side in to meaningful data. TCP takes care of sorting the packets and retransmitting lost ones.


Each message has a general header:
=== TCP Packet Format ===
* Size of message (4 bytes)
The network system is based on Messages being transmitted using TCP. There are two types of data stream; one from the Server to the Client and another one from the Client to the Server.


===TCP Client to Server communication stream===

The messages are sent one after each other over the TCP stream. TCP takes care of sorting the packets and retransmitting lost ones..

<b>Each message is composed of:</b>
* <i>Protocol version ( 1 byte )
* Type of Message ( 1 byte )
* Client ID ( 4 bytes )
* Rest of Message</i>

===TCP Server to Client communication stream===
Each message is held in one or more UDP Packets and the UDP Packet format is as follows: <br>

{{TODO|update this to reflect the new TCP based protocol
<b>1st UDP Packet is composed of:</b>
* <i>Total number of packets (1 byte)
* Position of this message (1 byte)
* Signature of the message (2 bytes)
* Protocol version (1 byte)
* Protocol version (1 byte)
* Type of Message (1 byte)
* Type of message (1 byte)
* Client ID (4 bytes)
* Client ID (4 bytes)
* Timestamp (4 bytes)
* Rest of Message</i>

<b>All other UDP Packets making up the one message are composed of:</b>
* <i>Total number of packets (1 byte)
* Position of this message (1 byte)
* Signature of the message (2 bytes)
* Rest of Message (up to 1497 bytes)</i>
}}

Messages are sent from the Server by simply serializing them. So the message itself contains the protocol version, the type of message and the Client id.


This header is followed by message specific data. Have a look at the [http://arianne.cvs.sf.net/viewvc/arianne/marauroa/src/marauroa/common/net/message source code] of the methods readObject() and writeObject() of the message in question.
Receiving the message is a bit more complex. First we need to determine that we are running a compatible version of the protocol by comparing the protocol version with the expected version in the message. Once we have agreed that the protocol is compatible we read the type of message and we ask the Message Factory ( see [[RolePlayingDesign]]) to build an object of that type with the corresponding data. Once the message is built we simply store it in a queue of incoming messages waiting to be processed.


==Network Manager==
==Network Manager==