Hi. I try to connect to remote host on port which closed, but connect() == 0 && WSAGetLastError() == 0, and second call of send() returns SOCKET_ERROR. If port is open all works perfectly. Therefore I can't determine was connection successful or not.
I using Visual Studio 2008, project with MFC.

Code:
int Rpc::Connect()
{
	ADDRINFOW 		hint;
	PADDRINFOW		pAi;
	sockaddr_in		sin;
	int				res=0;

	CSingleLock			lock(&mutex);

	lock.Lock();

	if (hSock != INVALID_SOCKET)
	{
		SetLoggedIn(false);
		closesocket(hSock);
		hSock=INVALID_SOCKET;
		connected=false;
	}

	memset(&hint,0,sizeof(hint));
	memset(&sin,0,sizeof(sin));
	
	hint.ai_family=AF_INET;
	hint.ai_socktype=SOCK_STREAM;
	hint.ai_protocol=IPPROTO_TCP;

	if (res=GetAddrInfoW(host_name,NULL,&hint,&pAi))
	{
		return res;
	}


	sin.sin_addr.S_un.S_addr=((sockaddr_in*)(pAi->ai_addr))->sin_addr.S_un.S_addr;
	sin.sin_family=AF_INET;
	sin.sin_port=htons(port);
	//sin.sin_addr=Ip("127.0.0.1").Addr();
	//sin.sin_port=htons(19);

	if ((hSock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET)
	{
		return WSAGetLastError();
	}

	if (connect(hSock,(sockaddr*)&sin,sizeof(sin)))
	{
		closesocket(hSock);
		hSock=INVALID_SOCKET;
		return WSAGetLastError();
	}

	connected=true;
	SetAsync();

	return 0;
}
Can anybody help me?