English 中文(简体)
Winsock 返回10061, 仅与当地东道方连接
原标题:Winsock returns 10061 on connect only to localhost

I dont understand whats happening. If I create a socket to anywhere else other than localhost (either "localhost", "127.0.0.1" or the external ip of the machine) it works fine. If I create a socket to an address without something listening in that port i would get a 10060 (timeout) but not a 10061 which makes sense. Why is it that I am getting connection refused when going to localhost. I tried disabling the firewall just in case it was messing things up, but that is not it

我在这样做之前,尽了一切力量。

    _socketToServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(_socketToServer == -1){
    return false;
    }

   p_int = (int*)malloc(sizeof(int));
   *p_int = 1;
   if( (setsockopt(_socketToServer, SOL_SOCKET, SO_REUSEADDR, 
       (char*)p_int, sizeof(int)) == -1 )||
       (setsockopt(_socketToServer, SOL_SOCKET, SO_KEEPALIVE, (char*)p_int,
               sizeof(int)) == -1 ) ){
        free(p_int);
        return false;
   }
   free(p_int);


   struct sockaddr_in my_addr;

   my_addr.sin_family = AF_INET ;
   my_addr.sin_port = htons(_serverPort);

   memset(&(my_addr.sin_zero), 0, 8);
   my_addr.sin_addr.s_addr = inet_addr(_serverIP);


   if( connect( _socketToServer, (struct sockaddr*)&my_addr, sizeof(my_addr)) 
        == SOCKET_ERROR ){
    DWORD error = GetLastError(); //here is where I get the 10061
    return false;
}

任何想法?

最佳回答

在连接另一台机器上的非上市港口时,不能保证你有<条码>WSAETIMEDOUT/code>的错误。 任何不同的错误都会发生。 然而,WSAETIMEDOUT的差错通常只有在下列情况下才会发生:在<代码>连接(前不能在网络上达到目标机。 如果能够达到目标机器,WSAECONNREFUSED的差错是指目标机器正在承认<代码>()的要求,并回答说,请求的港口当时无法接受这一联系,因为它不是听的,也不是全部积压(无法区分)。 因此,当你与当地东道方联系时,由于你与同一机器相联,因此在连接不列入名单的港口时,你总是会遇到“的错误,在确定港口的听力方面也没有延误。 它与防火墙或防疟疾无关。 这只是正常的行为。

问题回答

暂无回答




相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签