Game Development Reference
In-Depth Information
Since UDP doesn't keep track of lost packets, it doesn't need to be connected to the other
side. In fact, one socket can send multiple packets to different destinations with no prob-
Sending packets with UDP looks similar to TCP, the only difference is that we use the
sf::UdpSocket class:
Note that we don't have to connect before sending over our packet. The remote port and IP
address are needed only after we are ready to send the data across. The UdpSock-
et::send() method takes those as the last two parameters and returns a Sock-
et::Status (the same as the TcpSocket ). It is important to note that the status does
not tell us if the other side has received the data, but it only indicates that the current action
(in this case sending a packet) was successful or not. That means that the packet might not
arrive at its destination at all and that is absolutely fine with the sender — after all that is
part of the design behind UDP.
On the receiving end, the code looks like this:
Search WWH ::

Custom Search