Re: Why the client can't receive the response from server?
- From: "bucher" <bucher@xxxxxxxx>
- Date: Tue, 21 Nov 2006 09:40:18 +0800
Hi,
I want to send some data to the server. The server sent the response data
successfully, but the client can't receive data.
The code like below:
server side:
SOCKET hClient = accept(sktServer, 0, 0);
//...receive data
send(hClient, buffer, iLen, 0); //This statement executes successfully
shutdown(hClient, SD_BOTH);
closesocket(hClient);
client side:
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addrConnect;
addrConnect.sin_family = AF_INET;
addrConnect.sin_port = htons(m_uPort); //set port
addrConnect.sin_addr.s_addr = uAddr; //set address
connect(hSocket , (LPSOCKADDR)&addrConnect, sizeof(addrConnect));
//...send data
timeval timeout;
memset(&timeout, 0, sizeof(timeval));
timeout.tv_sec = 2;
timeout.tv_usec = 0;
fd_set fd_read_set;
FD_ZERO(&fd_read_set);
FD_SET(hSocket, &fd_read_set); //hSocket was used to send data to server
int errorRet = select(0, NULL, &fd_read_set, NULL, &timeout);
if(errorRet== SOCKET_ERROR){
//error
}else if(errorRet == 0){
//timeout
}else{
int bytesRead;
while ( (bytesRead = recv(hSocket, buffer, READ_BUFFER_SIZE, 0)) != 0)
{
if(bytesRead == SOCKET_ERROR){
TRACE("The error code in CClientSocket::WaitForReply is %d\n",
WSAGetLastError());
return FALSE;
}
//...
}
The errorRet is often set to 0 or the WSAGetLastError get the error code
10053. Can someone help me?
Thanks in advanced.
.
- References:
- Prev by Date: Link speed...
- Next by Date: Re: Why the client can't receive the response from server?
- Previous by thread: Re: Why the client can't receive the response from server?
- Next by thread: Re: IOCP with sockets
- Index(es):
Relevant Pages
|