12.07.2015 Views

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

closing connections immediately is undesired because a neighbor may leave the vision range just for ashort period <strong>of</strong> time and come back in which case closing and re-establishing the connection would bewasteful. And second, crashed nodes are detected the same way, as CUSP itself does not have connectiontimeouts.As specified by pSense, a node selects a sensor node for each sec<strong>to</strong>r <strong>to</strong> be the nearest node outside thevision range <strong>with</strong>in the section. When node A selects node B as its sensor node for a particular sec<strong>to</strong>r, itsends a sensor node request <strong>to</strong> B, including the sec<strong>to</strong>r which B is responsible for. B s<strong>to</strong>res this informationand keeps sending updates <strong>to</strong> A (although it is outside A’s vision range). A also has <strong>to</strong> keep sendingupdates, or otherwise B’s connection timeout will take effect. As both A and B are updated about eachother’s position, B may suggest other nodes as sensor nodes that are more appropriate (e.g., nearer) <strong>to</strong>A. When A decides <strong>to</strong> replace B <strong>with</strong> a new sensor node, it informs both B and the new node via sensornode request mesages. B then s<strong>to</strong>ps sending its updates <strong>to</strong> A (unless it is in A’s vision range) whichwill finally cause a connection timeout. Even if for some reason B is not properly informed about itsreplacement, A will s<strong>to</strong>p sending its updates and B’s connection <strong>to</strong> A will also time out. This provides acertain robustness against faulty nodes.MessagingLike in the client-server version, each connection between two peers consists <strong>of</strong> one permanent streamfor each direction which transports the regular update messages. For technical reasons, i.e., <strong>to</strong> preventCUSP from tearing down the channel, it is advisable <strong>to</strong> keep at least one stream permanently open.As already mentioned in the client-server section, there are certain advantages in sending each updatemessage in a separate stream instead <strong>of</strong> using the permanent stream. This concept is explained in alittle more detail in the following. When sending data trough a CUSP stream or a TCP connection,the application does not have any control over the amount <strong>of</strong> data that is buffered for sending or inflight <strong>to</strong> the receiver. While this is dispensable for non-realtime applications where it is just <strong>of</strong> interest <strong>to</strong>transfer a block <strong>of</strong> data (as fast as possible), update messages have very diffrent requirements for realtimeapplications. In many cases it is not important that every update message arrives at its destination, butit is important that updates get delivered as soon as possible. Both is easily fulfilled when the channelhas much more bandwidth available than required for sending the messages. But as soon as there iscongestion, reliable in-order pro<strong>to</strong>cols like TCP and CUSP have <strong>to</strong> buffer data before sending. And asthe application continues sending messages <strong>with</strong> a constant rate, buffers may fill up. Since the transportpro<strong>to</strong>col buffers are limited, the application will eventually notice that it has <strong>to</strong> interrupt sending data,e.g., via blocking write calls. But then, there are already potentially a lot <strong>of</strong> update messages buffered <strong>of</strong>which many are out <strong>of</strong> date.That is why realtime applications, especially games, tend <strong>to</strong> use UDP instead <strong>of</strong> TCP. UDP messages aresimply dropped in case <strong>of</strong> congestion. Thus, not all messages arrive, but those that arrive, are (usually)in time. But UDP does not make any guarantees about reliability and in-order delivery, requiring theapplication <strong>to</strong> take care <strong>of</strong> all these requirements where necessary. CUSP allows for a compromisebetween the two opposite solutions by using separate (prioritized) streams for each message; the streamis created, the message data is sent and the stream is shut down immediately. Except for a few headerbytes, this approach does not have any overhead compared <strong>to</strong> UDP, once CUSP has established a channel.The application may than assign increasing priorities <strong>to</strong> each message sent; the latest messages willconsequently be sent first if the channel is congested. If a message has not been acknowledged (theapplication is notified via the stream shutdown callback), it is likely <strong>to</strong> be still buffered and may beremoved via a stream reset call. If the message (including the stream shutdown indication) is already inflight, it will be delivered even after calling reset. The application only has <strong>to</strong> include timestamps <strong>to</strong> theupdate messages allowing <strong>to</strong> detect (and probably ignore) late messages.3 Concept 41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!