OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Creating a Datagram Socket

In the code below, a Datagram (UDP) Socket is created with several options (including broadcasting).

int MySocketUsingClass::SetupASocket(u_short nPeerPortInNetworkOrder, char* szPeerIPAddressDottedDecimal)
{
TINetSocketAddress myAddress; //(port 0, address INADDR_ANY)
TDatagramSocket myDatagramSocket(myAddress);
myDatagramSocket.CreateSocket();
myDatagramSocket.BindSocket();
myDatagramSocket.SetBroadcastOption(TRUE); //enable broadcasting.
myDatagramSocket.SetDebugOption(TRUE); //record
myDatagramSocket.SetLingerOption(TRUE, 5); //set linger to 5 seconds.
myDatagramSocket.SetSendBufferOption(512); //set send buffer size to 512
bytes.
myDatagramSocket.SetPeerAddress(TINetSocketAddress(ntohs(N_PORT), INADDR_BROADCAST);
}