Socket高手救我,我为什么老是connect失败???急。。。。
我在做一个面向TCP(stream式)的链接,我是客户端,我为什么老是connect失败???我的代码如下:
g_nServerPort[0]=sFirstPort;
g_nServerPort[1]=sSecondPort;
int i=0;
for(i=0;i<2;i++)////prepare to setup the 2 TCP links
{
g_ClientSocket[i] = socket(AF_INET, SOCK_STREAM, 0);
if(g_ClientSocket[i]==INVALID_SOCKET)
{
MessageBox( NULL,"create client socket error", NULL,MB_OK);
return FALSE;
}
////the info of the server socket
g_sockServerAddr[i].sin_family = AF_INET;
ulIP = inet_addr(sServerIP);
if ( INADDR_NONE != ulIP )
g_sockServerAddr[i].sin_addr.S_un.S_addr = ulIP;
else
{
MessageBox( NULL, "server IP error", NULL, MB_OK);
return FALSE;
}
int nErrorCode = WSAAsyncSelect(g_ClientSocket[i],hWnd,WM_RCV1+i*10, FD_READ);
if (nErrorCode == SOCKET_ERROR)
{
MessageBox( NULL, "asyncselect error", NULL, MB_OK);
return FALSE;
}
}
int nRet;
nRet=connect(g_ClientSocket[0],(LPSOCKADDR)&g_sockServerAddr[0],sizeof(g_sockServerAddr[0]));
if (nResponse!=0)
{
nErrorCode=WSAGetLastError();
str.Format("错误号%d",nErrorCode);
MessageBox( NULL,"connect to the server error! "+str, NULL, MB_OK);
return -1;
}
bConnected[0] = TRUE;
服务器端能够acccept,connect()失败后取到的错误码是10035:引用指针错误。