// The thread passes a handle to the edit control to the receive function so tell us what's u.
while(WaitForSingleObject(hStopEvent, 0) != WAIT_OBJECT_0) { // ...When it's Time for it.
if(bPortChange) {
SetEvent(hStopEvent);
}else{
Listen4Ping(g_hEdit, s);
}
}
//===========================================================================================
//-------------------------------------------------------------+++--> Tell User What You Hear!
void Listen4Ping(HWND hEdit, SOCKET soc) { //------------------------------------------+++-->
TCHAR recvbuf[MAX_BUFF] = {0};
TCHAR szTemp[GEN_BUFF] = {0};
SOCKADDR_IN saPong; // IP Address Structure for Local Listener.
int iSenderAddrSize = sizeof(saPong);
int iResult;
timeval tv; // Time Value Object
fd_set fd; // File Descriptor Set
fd.fd_count = 1; //----//-+++--> Number of sockets in the set.
fd.fd_array[0] = soc; // Array of sockets that are in the set.
tv.tv_sec = 1; // Set Timer Value to Wait Only 1 second...
tv.tv_usec = 0; // With No Additional microseconds to wait.
iResult = select(1, &fd, NULL, NULL, &tv);
if(iResult > 0) {
SOCKET Accpt;
int iBytesRecv;
Accpt = accept(soc,(SOCKADDR *)&saPong, &iSenderAddrSize);
StringCbPrintf(szTemp, GEN_BUFF, "\r\nConnected Client's IP: %s", inet_ntoa(saPong.sin_addr));
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)szTemp);
iBytesRecv = recv(Accpt, recvbuf, MAX_BUFF, 0);
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)recvbuf);
StringCbPrintf(szTemp, GEN_BUFF, "\r\nBytes Received: %ld\r\n\r\n", iBytesRecv);
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)szTemp);
if(Accpt) closesocket(Accpt);
}else{
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)".");
}
} // Here I get output of something every second regardless of a connection. That was if something does go wrong is obvious even if it isn't bad enough to lock the entire app.