WSA Refusing connection - howto find out the server refused connection?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: WSA Refusing connection - howto find out the server refused connection?

  1. #1
    Join Date
    Sep 2007
    Location
    CZ
    Posts
    14

    WSA Refusing connection - howto find out the server refused connection?

    hi, im refusing connection by server, if the client is on the black list. but i cant find out (in the client code), the serve refused.
    the client code is:
    Code:
            struct sockaddr_in ServerAddress;
    
    	SOCKET Socket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
    
    	if (INVALID_SOCKET == Socket) 
    	{
    		ErrorExit("WSASocket error", WSAGetLastError());
    		return SOCKET_ERROR; //error
    	}
    
    	WSAEVENT eevent = WSACreateEvent();
    
    	WSAEventSelect(Socket, eevent, FD_CONNECT);
    
    
    	ZeroMemory((char *) &ServerAddress, sizeof(ServerAddress));
    
    
    	ServerAddress.sin_family = AF_INET;
    	ServerAddress.sin_addr.S_un.S_addr = ulIp;
    	ServerAddress.sin_port = htons(nPortNo);
    
    	
    	if (SOCKET_ERROR == WSAConnect(Socket, reinterpret_cast<const struct sockaddr *>(&ServerAddress),sizeof(ServerAddress), 
    		NULL, NULL, NULL, NULL)) 
    	{
    		int iErrCode = WSAGetLastError();
    		if(iErrCode != WSAEWOULDBLOCK)
    		{
    			closesocket(Socket);
    			ErrorExit("WSAConnect error", iErrCode);
    			return SOCKET_ERROR; //error
    		}
    	}
    
    	DWORD retCode = WSAWaitForMultipleEvents(1, &eevent, TRUE, INFINITE, FALSE);
    	WSANETWORKEVENTS NetworkEvents;
    	if((retCode != WSA_WAIT_FAILED) && (retCode != WSA_WAIT_TIMEOUT))
    	{
    		if(WSAEnumNetworkEvents(Socket, eevent, &NetworkEvents) == SOCKET_ERROR)
    		{
    			int iErrCode = WSAGetLastError();
    		}
    		if((NetworkEvents.lNetworkEvents & FD_CONNECT ) == FD_CONNECT)
    		{
    			int iErrCode = WSAGetLastError();
    			if(iErrCode == WSAECONNREFUSED)
    			{
    				ErrorExit("Server refuse!", iErrCode);
    				return SOCKET_ERROR;
    			}
    		}
    	}
    
    	return Socket;
    the WSAECONNREFUSED error never occurs. how it is possible? whats wrong? im sure the server refuse connection.
    thanks

  2. #2
    Join Date
    Mar 2001
    Posts
    2,363

    Re: WSA Refusing connection - howto find out the server refused connection?

    Perhaps it is occurring at the router frame or some other firewall. Have you tested a traceroute?
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Sep 2007
    Location
    CZ
    Posts
    14

    Re: WSA Refusing connection - howto find out the server refused connection?

    i will try it. its some possibility to fix it? the FD_CONNECT event occurs but WSAECONNREFUSED error not.

  4. #4
    Join Date
    Sep 2007
    Location
    CZ
    Posts
    14

    Re: WSA Refusing connection - howto find out the server refused connection?

    i cant capture packets in wireshark or ethereal because they cant capture localhost packets. i tried to fix it like this http://wiki.wireshark.org/CaptureSetup/Loopback but it didnt fix it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center