NetworkDesign: Difference between revisions

Content deleted Content added
imported>Hendrik Brummermann
No edit summary
imported>Hendrik Brummermann
No edit summary
Line 2:
{{Navigation for Marauroa Developers}}
 
 
{{Likely Outdated}}
 
Please note: This page explains the low level network communication. You don't need to bother with these implementation details if you want to use Marauroa to write a game. We document the network design anyway for contributor to Marauroa itself. And it is helpful for people porting Marauroa to other programming languages.
Line 17 ⟶ 15:
 
[[Image:messages-connected.png|thumb|Messages used to securely login.]]
{{br}}
 
=== State logged in ===
 
[[Image:messages-loggedin.png|thumb|Selecting a character and transmitting world meta data.]]
{{br}}
 
=== State in game ===
 
[[Image:messages-game.png|thumb|Messages sent while the game is active.]]
{{br}}
 
=== Logging Out ===
Line 30 ⟶ 31:
[[Image:messages-logout.png|thumb|The client sends a logout request and the server accepts or denies it.]]
 
{{br}}
 
== Transmitting Messages over TCP ==
 
== Basic idea behind Networking ==
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.
 
Line 78 ⟶ 79:
* Finalizing the manager
 
The read operation is a blocking type operation so we have two options, either Pollingpolling (i.e. continually checking if data is there) or Blockingblocking (i.e. only processing when data is actually available, otherwise sleeping).
 
We choose Blockingblocking because we don't want to waste CPU time Pollingpolling 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 ReadNetworkManagerRead.
(<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 ManagerNetworkManager 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.
Line 107 ⟶ 106:
{
get from pendingToSendMessages
build UDP fromserialize message
send socket
}
Line 115 ⟶ 114:
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 Writewrite 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 is no guarantee that the message is correctly sent. This situation is part of the protocol itself.
 
The Readread method is blocking, when you call the Readread 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. Note that the manager just sends the stream of packets once and doesn't confirm if any of the messages are received. PleaseTCP refertakes tocare [[NetworkDesign#UDP_Packet_Formatof | UDP Packet Format]] for more info about itthat.