OWLNext 7.0
Borland's Object Windows Library for the modern age
|
The code below sends a C string by datagram to a given peer on a given port.
Both blocking and non-blocking code is demonstrated. Note that the switch back and forth between blocking and non-blocking mode involves only a single line of code. Note also that after the last write call, the local TDatagramSocket object is deleted without any closesocket() function being called. This is because the socket cleans up after itself and calls CloseSocket() if it had not been called already.
The code below broadcasts a C string on the network, minus error-checking. Note that when you broadcast with the address "INADDR_BORADCAST", you don't need to say htonl(INADDR_BROADCAST) or inet_addr(INADDR_BORADCAST). This is because the definition for INADDR_BROADCAST and its related predefined addresses are already in binary network format.