Protocol
Using DarkNet you can use TCP and UDP networking protocols together in order to take full advantage of each protocol.
The remainder of this page explains how each should be used together to create high performance applications.
UDP
UDP packets can be sent and received using mnSendUDP and mnRecvUDP DarkNet commands.
UDP packets have the following characteristics:
- Packets are not guaranteed to arrive, some may be discarded.
- Transfer is usually faster than TCP.
- Packets may arrive out of order. Note: options to enforce order and discard out of order packets exist in DarkNet.
An example use for UDP is sending microphone audio. It is not essential that all messages arrive; losing a couple milliseconds of audio here and there is not a major problem. Out of order packets should be ignored, DarkNet can do this for us. Speed is important as we do not want to hear someone speaking when they spoke many seconds ago.
The first UDP packet sent (1) is going to be received after the second UDP packet (2) because it experienced problems on its journey. The third UDP packet (3) will never be received because it was lost in transit.
Broadcasting
Broadcasting (which uses UDP) can be used to send data to all devices on a LAN.
This is most commonly used by applications that want to announce their presence so that clients can connect to them.
Screenshot from the Cube World Advanced demo:

TCP
TCP packets can be sent and received using mnSendTCP and mnRecvTCP DarkNet commands.
In reality TCP packets suffer the same problems as UDP, but the protocol ensures that TCP packets have the following characteristics:
- They arrive in the order that they are sent (first sent, first received).
- No packets are dropped, they are guaranteed to reach their destination.
- Transfer is optimized; packets may be sent bundled together or in parts in order to reduce congestion.
- Transfer is usually slower than UDP.
An example use for TCP would be to send chat messages. It is essential that these messages arrive and are not dropped, and it is useful that they arrive in order. Slower transfer is not a major problem.
The protol enforces order and ensures delivery of all packets:
|