UDT Tutorial |
UDT3 added new functionalities of data messaging with partial reliability. Previously in UDT2, data is regarded as streams; there is no concept of message. The streaming functionality is still kept in UDT3, but in UDT3, you have the choice to keep the message boundaries. Furthermore, you can specify if a particular message should be deliver in order or how long it should be kept in the sender buffer (time-to-live, or TTL).
In UDT3, when a socket is created using SOCK_STREAM mode, streaming mode is used; when a socket is created using SOCK_DGRAM, messaging mode is used. In messaging node, sendmsg and recvmsg are used to send and receive a message, respectively.
For example:
UDTSOCKET u = UDT::socket(AF_INET, SOCK_DGRAM, 0);
char data[1024]; int size = 1024;
int ssize = UDT::sendmsg(client, data,
size, -1, false); int rsize = UDT::recvmsg(u, data, size); |
sendmsg can specify for each single message a TTL value. A negative value means infinite TTL, or the message must be delivered. If a positive value is specified but the message has not be delivered in that time period, the message will de discarded. A boolean flag can also be used to specify if the message should be delivered in order, which means the message cannot be received by the peer side unless all the messages prior to it have been either received or discarded.
Both sendmsg and recvmsg can be used in either blocking mode or non-blocking mode. However, overlapped IO does not applied to these two methods.
Note:
While messaging API meets the requirements for certain applications, it takes more overhead to provide these new functionalities. Therefore, it is possible to observe a lower performance when using SOCK_DGRAM than when using SOCK_STREAM.