It is written here that a client class is written. When the initnetClient is successfully connected, the server is connected, and the received data returns the window. After other functions, add it ./************************************** ************************************************************************************************************************************************************************************************************************************************* 2004 - 11 - 30 Refer to MSDN Stephen ***************************************************************************** ***************** / #include
= NULL) {WSPrintf (this-> szerror, text ("gethostbyname failed.error:% d"), wsagetlasterror (); clossockt (serversocket); return false;} Memcpy (Destination.sin_Addr ), phostent-> h_legth; destination.sin_port = htons (port); return true;} // Connect server BOOL CNETCLIENT :: ConnectTOSERVER () {IF (serversocket == invalid_socket) Return False; IF connect (serverSocket, (PSOCKADDR) & destination, sizeof (destination)) == SOCKET_ERROR) {wsprintf (this-> szError, TEXT ( "connect failed.Error:% d"), WSAGetLastError ()); closesocket (serverSocket); return false;} hreadthread = CreateThread (Null, 0, CNetClient :: Threadtoread, this, 0, null); return true;} // Send Data BOOL CNETCLIENT :: SendDatatoserver (CHAR * DATA, INT LEN) {if (ServerSocket == INVALID_SOCKET) RETURN FALSE; IF (Send (Serversocket, Data, Len, 0) == Socket_ERROR) {WSPrintf (this-> szerror, text ("send failed.error:% D"), wsagetlasterror ()); CloseSocket (Serversocket Return false;} return true;} // Return Error message char * CNETCLIENT: : GetLastError () {return this-> szerror;} // Read data thread DWord WinAPI CNetClient :: threadtoread (lpvoid n) {CNETCLIENT * PNETCLIENT = (CNetClient *) n; while (1) {pnetClient-> nReceive = Recv (PNETCLIENT-> Serversocket, PnetClient-> getData, sizeof (pnetClient-> getdata), 0); if (pnetClient-> nReceive == Socket_ERROR) {WSPrintf (pnetclient-> szerror, text ("RECV FAILED.Error:% D "), wsagetlasterror ()); CloseSocket (PNETClient-> ServerSocket); Break;} else if (pnetClient-> NReceive == 0) {WSPrintf (PNETClient-> Szerror, Text (" Finished Receiving Data "); CloseSocket (pnetClient-> serversocket);