NetworkDesign: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
imported>StephenIerodiaconou No edit summary |
||
| Line 1: | Line 1: | ||
= Basic idea behind Networking = |
= Basic idea behind Networking = |
||
The idea behind arianne network protocol is to use a single stream of UDP packets |
The idea behind arianne's network protocol is to use a single stream of UDP 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. |
||
== UDP Packet Format == |
== UDP Packet Format == |
||
The |
The network system is based on Messages being transmitted using UDP Packets. There are two types of data stream; one from the Server to the Client and another one from the Client to the Server. |
||
===UDP Client to Server communication stream=== |
===UDP Client to Server communication stream=== |
||
Each message is |
Each message is contained in a SINGLE UDP Packet. There is no mechanism for recovery of lost or repeated messages. |
||
Each UDP Packet is composed of: |
<b>Each UDP Packet is composed of:</b> |
||
*Protocol version ( 1 byte ) |
* <i>Protocol version ( 1 byte ) |
||
*Type of Message ( 1 byte ) |
* Type of Message ( 1 byte ) |
||
*Client ID ( 4 bytes ) |
* Client ID ( 4 bytes ) |
||
*Rest of Message ( up to 1494 bytes ) |
* Rest of Message ( up to 1494 bytes )</i> |
||
===UDP Server to Client communication stream=== |
===UDP Server to Client communication stream=== |
||
Each message is |
Each message is held in one or more UDP Packets and the UDP Packet format is as follows: <br> |
||
1st UDP Packet is composed of: |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<b>1st UDP Packet is composed of:</b> |
|||
*Total number of packets (1 byte) |
* <i>Total number of packets (1 byte) |
||
*Position of this message (1 byte) |
* Position of this message (1 byte) |
||
*Signature of the message (1 byte) |
* Signature of the message (1 byte) |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<b>All other UDP Packets making up the one message are composed of:</b> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
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. |
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. |
||
Receiving the message is a bit more complex. First we need to determine that we are running a compatible version of the protocol. Once we have agreed that the protocol is compatible we read the type of message and we ask |
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 ( "Java Design Patterns" ) to build an object of that type with the corresponding data. Once the message is build we simply store it in a queue of incoming messages waiting to be processed. |
||
=Network Manager= |
=Network Manager= |
||
The Network Manager is our router that sends and receives messages to and from the network. The manager exposes the interfaces that allow: |
The Network Manager is our router that sends and receives messages to and from the network. The manager exposes the interfaces that allow: |
||
*Reading a message from the network |
* Reading a message from the network |
||
*Sending a message to the network |
* Sending a message to the network |
||
*Finalizing the manager |
* Finalizing the manager |
||
The read operation is a blocking type operation so we have two options, either Polling (i.e. continually checking if data is there) or Blocking (i.e. only processing when data is actually available, otherwise sleeping). |
|||
(<i>Polling is "the sequential interrogation of devices for various purposes, such as avoiding contention, determining operational status, or determining readiness to send or receive data." - Wikipedia (http://en.wikipedia.org/wiki/Polling)</i>) |
|||
We choose Blocking because we don't want to waste CPU time Polling the network for messages, we just want to sleep until messages are available. Hence we create a Thread to read from the Network, let's call it Network Manager Read. |
|||
Writing messages to the network can be simply coded as a method of Network Manager, as write is an operation that is non blocking by nature. |
|||
The Network Manager opens a Socket from which it will receive all the messages from the network |
The Network Manager opens a Socket from which it will receive all the messages from the network. It will also write all the outbound messages to the network from this same socket. Note: Both write and read use the same Socket. ( |
||
To encapsulate all this we create both the Read and Write methods as inner classes of Network Manager. |
To encapsulate all this we create both the Read and Write methods as inner classes of Network Manager. |
||
| Line 74: | Line 79: | ||
</pre> |
</pre> |
||
As you can see, messages are stored in a list when they are received |
As you can see, messages are stored in a list when they are received. Hence access to the list must be synchronized. |
||
Now lets get back to the interface as exposed to other objects. The Write method is immediate, just call it with the message to send, making sure that you have correctly filled SourceAddress and ClientID |
Now lets get back to the interface as exposed to other objects. The Write method is immediate, just call it with the message to send, making sure that you have correctly filled SourceAddress and ClientID. The message will then be sent to the Client. |
||
It is important to notice that as the transport is based on UDP there |
It is important to notice that as the transport is based on UDP there is no guarantee that the message is correctly sent. This situation is part of the protocol itself. |
||
The Read method is blocking, when you call the Read method it either returns a message from the queue or if the queue is empty the thread blocks until one arrives. |
The Read method is blocking, when you call the Read method it either returns a message from the queue or if the queue is empty the thread blocks (sleeps) until one arrives. |
||
That is the basic idea of the Network Manager; however, the manager gets a bit more complex as a result of the need to support Server to Client messages that are bigger than one UDP package |
That is the basic idea of the Network Manager; however, the manager gets a bit more complex as a result of the need to support Server to Client messages that are bigger than one UDP package. Note that the manager just sends the stream of packets once and doesn't confirm if any of the messages are received. Please refer to UDP Packet Format for more info about it. |
||
=Message Types= |
=Message Types= |
||
To communicate, the Client and Server of Marauroa use a stream of UDP packets. The message system belongs to the marauroa.common.net package, so refer to code. |
To communicate, the Client and Server of Marauroa use a stream of UDP packets. The message system belongs to the marauroa.common.net package, so refer to the code for a detailed knowledge of the system. |
||
We have Client to Server, aka C2S, and Server to Client, aka S2C, messages. <br> |
We have Client to Server, aka C2S, and Server to Client, aka S2C, messages. <br> |
||
| Line 133: | Line 138: | ||
==Message C2S Login== |
==Message C2S Login== |
||
The login Message is sent from the Client to the Server to request the right to access to the game. The message is composed of a username and password. The Username is a string that is already registered on Server as the name of a user account |
The login Message is sent from the Client to the Server to request the right to access to the game. The message is composed of a username and password. The Username is a string that is already registered on the Server as the name of a user account. Password is a string that is associated with that account. If the username/password combination is correct then the Server must send a Login ACK Message to indicate to the Client that the message has been correctly processed. However, if the username/password is wrong the Server will send a Login NACK (Not ACKnoledge). |
||
==Message S2C Login ACK== |
==Message S2C Login ACK== |
||
| Line 151: | Line 156: | ||
==Message S2C Server Info== |
==Message S2C Server Info== |
||
The Server Info Message is |
The Server Info Message is sent from the Server to the Client to tell the Client about what Server is running, and details on how to inform the Server administrator of any problems (e.g. their email address). |
||
The message is composed of: A List of strings of the type "attribute=value" |
The message is composed of: A List of strings of the type "attribute=value" |
||
| Line 167: | Line 172: | ||
==Message S2C Choose Character ACK== |
==Message S2C Choose Character ACK== |
||
The Choose Character ACK Message is sent from the Server to the Client to notify the Client that the character has been chosen. |
The Choose Character ACK Message is sent from the Server to the Client to notify the Client that the character has been chosen. |
||
The message is composed of: the object.ID of the character |
|||
We need this value to track our own character. |
We need this value to track our own character. |
||
| Line 194: | Line 201: | ||
The Action message is sent from the Client to the Server to notify the Server of the Clients desire to execute an action. The message is simply composed of a single action. |
The Action message is sent from the Client to the Server to notify the Server of the Clients desire to execute an action. The message is simply composed of a single action. |
||
==Message S2C Action ACK== |
|||
The Action ACK is sent from the Server to the Client to identify that the action has been received in the Server. It doesn't acknowledge that the action has been accepted by the RP Manager, it just means that the action successfully arrived at the Server. |
The Action ACK is sent from the Server to the Client to identify that the action has been received in the Server. It doesn't acknowledge that the action has been accepted by the RP Manager, it just means that the action successfully arrived at the Server. |
||
| Line 200: | Line 207: | ||
==Message S2C Perception== |
==Message S2C Perception== |
||
The Perception message is a message sent from the Server to the Client to notify the Client about changes to the objects that exist near it. The message is based on the idea explained in Delta |
The Perception message is a message sent from the Server to the Client to notify the Client about changes to the objects that exist near it. The message is based on the idea explained in Delta Perception document. |
||
The message is composed of: |
The message is composed of: |
||
*A type that can be DELTA or TOTAL |
* A type that can be DELTA or TOTAL |
||
*A string indicating the name of the zone the perception is related to. |
* A string indicating the name of the zone the perception is related to. |
||
*A time stamp value that will be just one unit bigger than the previous perception |
* A time stamp value that will be just one unit bigger than the previous perception |
||
*A List of RPObject that contains added object |
* A List of RPObject that contains added object |
||
*A List of RPObject that contains modified added object attributes |
* A List of RPObject that contains modified added object attributes |
||
*A List of RPObject that contains modified deleted object attributes |
* A List of RPObject that contains modified deleted object attributes |
||
*A List of RPObject that contains deleted object |
* A List of RPObject that contains deleted object |
||
*A RPObject that |
* A RPObject that describes the things the rest of players don't see about OUR own object. |
||
Read the Delta perception algorithm to understand what it is for. |
Read the Delta perception algorithm to understand what it is for. |
||
| Line 218: | Line 225: | ||
==Message S2C TransferREQ== |
==Message S2C TransferREQ== |
||
The TransferREQ message is a message sent from the Server to the Client to notify the Client |
The TransferREQ message is a message sent from the Server to the Client to notify the Client of the server's desire to send content useful for game play. |
||
The message is composed of: An array of TransferContent objects containing |
The message is composed of: An array of TransferContent objects containing the name of each resource, its timestamp and if the resource is cacheable or not. |
||
==Message C2S TransferACK== |
==Message C2S TransferACK== |
||
| Line 232: | Line 239: | ||
The message is composed of: An array of TransferContent objects containing all the name of each resource, its timestamp, a flag indicating if the resource is cacheable or not and a byte array with the content itself. |
The message is composed of: An array of TransferContent objects containing all the name of each resource, its timestamp, a flag indicating if the resource is cacheable or not and a byte array with the content itself. |
||
=Versioning and port numbering= |
==Versioning and port numbering== |
||
A problem arises when we need to have two versions of Marauroa on the same machine. This happens for example when you run a release version and a development version on the same machine. |
A problem arises when we need to have two versions of Marauroa on the same machine. This happens for example when you run a release version and a development version on the same machine. |
||