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

The code below reads data from a socket.

Since this is a datagram example, we simply read the next datagram that gets received. It is important to note that Windows Socket classes don't consider a WSAEWOULDBLOCK return from Recv() as an error. Thus, when you call Read() in non-blocking mode, and the Read() internally encounters a WSAEWOULDBLOCK, it simply sets nBytes to zero and returns without an error. Only real errors are returned by Windows Socket functions.

myDS.CreateSocket();
myDS.BindSocket();
myDS.StartRegularNotification(); //Turns on -non-blocking mode.
...
int nError;
char chBuffer[1000];
int nBytes=1000;
SocketAddress sAddressOfSender;
MessageBox(hWnd, TSocketError(nError).GetReasonString(), "Sockets Error", MB_OK);
}
if(nBytes){
ProcessTheBytes(chBuffer, nBytes); //Some function you may have made.
}
...
#define WINSOCK_ERROR
Definition wskhostm.h:31