Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. TCP help

TCP help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++sysadmintutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    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)

    J 1 Reply Last reply
    0
    • N NewHSKid

      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)

      J Offline
      J Offline
      Jesus Oliva
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups