Using UDP
In contrast to TCP, UDP is unreliable and connectionless. Neither the order of packets, nor their delivery is guaranteed. UDP, however, is very fast. So, if you have frequent data, which does not necessarily need to be received by the peer, use UDP. This data could, for example, be real-time positions of a player that get updated frequently or live video/audio streaming. Since QUdpSocket
is mostly the same as QTcpSocket
—both inherit QAbstractSocket
—there is not much to explain. The main difference between them is that TCP is stream-orientated, whereas UDP is datagram-orientated. This means that the data is sent in small packages, containing among the actual content, the sender's as well as the receiver's IP address and port number. Due to the lack of QUdpServer
, you have to use QAbstractSocket::bind()
instead of QTcpServer::listen()
. Like listen()
, bind()
takes the addresses and ports that are allowed to send datagrams as arguments. Whenever a new package...