wangyouhua
2003-07-07 02:24:01 UTC
In my App, i try to connect to an fixed address and port. It check
connection by interval, and call Connect() if the connection was break.
BOOL CMyAsyncSocket::Connect(const SOCKADDR *lpSockAddr, int nSockAddrLen)
{
ASSERT(m_hSocket!=INVALID_SOCKET);
unsigned long arg = 1;
ioctlsocket(m_hSocket, FIONBIO, &arg);
connect(m_hSocket, lpSockAddr, nSockAddrLen) != SOCKET_ERROR;
int nError = GetLastError();
return ( (nError== WSAEWOULDBLOCK) ? 1 : 0 );
}
If the Server(on remote station) is started for the first time, then my App
call CMyAsyncSocket::Connect() correctly(GetLastError()==WSAEWOULDBLOCK).
If i the Server is stop and then start. Because it found that connection was
break, My App handle the OnClose and create a new client socket and then
call CMyAsyncSocket::Connect() secondly . But this time, GetLastError
function in CMyAsyncSocket::Connect() return a value: WSAEINVAL.
Can anyone give my some hints to solve this problem?
Thanks.
connection by interval, and call Connect() if the connection was break.
BOOL CMyAsyncSocket::Connect(const SOCKADDR *lpSockAddr, int nSockAddrLen)
{
ASSERT(m_hSocket!=INVALID_SOCKET);
unsigned long arg = 1;
ioctlsocket(m_hSocket, FIONBIO, &arg);
connect(m_hSocket, lpSockAddr, nSockAddrLen) != SOCKET_ERROR;
int nError = GetLastError();
return ( (nError== WSAEWOULDBLOCK) ? 1 : 0 );
}
If the Server(on remote station) is started for the first time, then my App
call CMyAsyncSocket::Connect() correctly(GetLastError()==WSAEWOULDBLOCK).
If i the Server is stop and then start. Because it found that connection was
break, My App handle the OnClose and create a new client socket and then
call CMyAsyncSocket::Connect() secondly . But this time, GetLastError
function in CMyAsyncSocket::Connect() return a value: WSAEINVAL.
Can anyone give my some hints to solve this problem?
Thanks.