TCP help
-
Hi all, I have an app done in MFC, but I am having some problems with the ethernet part. My app is the client end that connects perfectly fine with a server up and running. The problem I am running into is when the server is not up but I type in the IP of it. It continues to say that it is connect. The only error that I ignore is error #10035 WSAEWOULDBLOCK. (i was told that this was an "OK" error) Basically as long as the IP or host name I enter is valid it says it is connected even though there is nothing there to connect to. How do I fix this problem so it recognize errors such as #10064 WSAEHOSTDOWN or #11001 WSAEHOST_NOT_FOUND Can someone also please tell me to how to check if at anytime that the connection is lost, reset by peer (or any other error that occurs that will not let me send data to the server) occurs how to immediately tell the user? Here is the code I am using:
int connection = sock->Create(0, SOCK_STREAM, FD_READ | FD_WRITE, NULL ); if (connection == FALSE) { int ret = sock->GetLastError(); m_Listbox.AddString("Failed to create socket"); } else m_Listbox.AddString("Socket Created"); int rVal = sock->Connect(servername, port) ; if (rVal == FALSE) { int ret = sock->GetLastError(); if(ret == WSAEWOULDBLOCK) { // Left blank for blocking } else { m_Listbox.AddString("Didn't connect"); return; } } else m_Listbox.AddString("Connected");
Many thanks in advance Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
-
Hi all, I have an app done in MFC, but I am having some problems with the ethernet part. My app is the client end that connects perfectly fine with a server up and running. The problem I am running into is when the server is not up but I type in the IP of it. It continues to say that it is connect. The only error that I ignore is error #10035 WSAEWOULDBLOCK. (i was told that this was an "OK" error) Basically as long as the IP or host name I enter is valid it says it is connected even though there is nothing there to connect to. How do I fix this problem so it recognize errors such as #10064 WSAEHOSTDOWN or #11001 WSAEHOST_NOT_FOUND Can someone also please tell me to how to check if at anytime that the connection is lost, reset by peer (or any other error that occurs that will not let me send data to the server) occurs how to immediately tell the user? Here is the code I am using:
int connection = sock->Create(0, SOCK_STREAM, FD_READ | FD_WRITE, NULL ); if (connection == FALSE) { int ret = sock->GetLastError(); m_Listbox.AddString("Failed to create socket"); } else m_Listbox.AddString("Socket Created"); int rVal = sock->Connect(servername, port) ; if (rVal == FALSE) { int ret = sock->GetLastError(); if(ret == WSAEWOULDBLOCK) { // Left blank for blocking } else { m_Listbox.AddString("Didn't connect"); return; } } else m_Listbox.AddString("Connected");
Many thanks in advance Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
The error WSAWOULDBLOCK not indicate that all was right. This code is returned because you are using non-blocking sockets and the operation can't be completed(you have a pending connect). After it, you have to use select api (unless you are using WSAAsyncSelect or WSAEventSelect) to check when the operation is completed. When this occur(after connection timeout), then check the error code of the operation and you will see that the connection can't be established.