Answer the question
In order to leave comments, you need to log in
C++.Sockets.RECV function
here is my question before that:
I do everything as it should be, I open a socket on the client and the server .. it comes to the moment when the server application should listen to the client (I use the recv function for this), the problem is that I threw it into the timer and when it has to execute it, it hangs stupidly and I’m waiting for something to come, I’m racking my brains, I don’t know how to solve this problem correctly, I’m already tired of looking in Google.
fd_set read_set, error_set;
struct timeval tv = {0,0};
tv.tv_sec = 1;
tv.tv_usec = 0;
FD_ZERO(&read_set);
FD_ZERO(&error_set);
FD_SET(sa, &read_set);
FD_SET(sa, &error_set);
if (select(sa + 1, &read_set, NULL, &error_set, &tv) == 1)
{
if (FD_ISSET(sa, &read_set))
{
bytesRecv = recv(sa, recvbuf, 50, 0);
err = WSAGetLastError();// 10057 = A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call)
if (bytesRecv == 0 || bytesRecv == WSAECONNRESET) {
textBox1->Text = "Connection Closed.\n";
WSACleanup();
}
else{
textBox1->Text = gcnew String(recvbuf);
}
};
Answer the question
In order to leave comments, you need to log in
I found the select function, I thought it might help, but nothing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question