I need to send multiple request (command) to server at port 55005.
My first request get process successfully & I received out put also.
But for second request it gives error (WSAESHUTDOWN – Error 10058).
After first request I call
shutdown(ConnectSocket, SD_SEND);
Then only server process the first request & send me output.
Now can re-open socket processing next request ?**
How I can process multiple request after shutdown(ConnectSocket, SD_SEND) ?
Thanks in Advance for your suggestions.
I send the first request , wait for first reply. After first request reply, I can send next request. This is business logic requirement. I don’t want to open a new connection for each request.
Snapshot Code start here —————->
**//This for loop will send multiple request to Servers.**
for(it = CommandList.begin(); it != CommandList.end() ; it++ )
{
//get each command request & send it to server.
std::string sendBuf; // = (*it);
sendBuf= *it;
int length = (int)strlen(sendBuf.c_str());
//----------------------
// Send an initial buffer
iResult = send( ConnectSocket, (char*)sendBuf.c_str(), length, 0 );
if (iResult == SOCKET_ERROR) {
wprintf(L"send failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
printf("Bytes Sent: %d\n", iResult);
// shutdown the connection since no more data will be sent
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
wprintf(L"shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
wprintf(L"Bytes received: %d\n", iResult);
else if ( iResult == 0 )
wprintf(L"Connection closed\n");
else
wprintf(L"recv failed with error: %d\n", WSAGetLastError());
} while( iResult > 0 );
}
As Joachim said, don’t call
shutdownuntil you are done with the connection. This TCP socket is a “stream”… stuff can go back and forth at will. You as a programmer have to determine where “requests” and “responses” begin and end… don’t useshutdownfor that.