|
char *sIp="192.168.11.105";
int nPort = 3000;
int rc;
WSADATA wsaData;
//SOCKET nConnect;
sockaddr_in sAddr;
struct hostent *nhost=NULL;
rc = WSAStartup( MAKEWORD(2 ,2 ), &wsaData );
if( rc != 0 ){
AfxMessageBox( TEXT("WSAStartup Error" ) );
return;
}
BYTE lb = LOBYTE( wsaData.wVersion );
BYTE hb = HIBYTE( wsaData.wVersion );
if( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
AfxMessageBox(TEXT("WSAStartup Version Error" ) );
WSACleanup( );
return;
}
int nsock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if( nsock == INVALID_SOCKET ){
AfxMessageBox(TEXT("socket Error" ) );
WSACleanup( );
return;
}
memset( &sAddr , 0 , sizeof( sAddr ) );
sAddr.sin_family = AF_INET;
sAddr.sin_port = htons( nPort );
sAddr.sin_addr.s_addr = inet_addr(sIp );
if( sAddr.sin_addr.s_addr == INADDR_NONE ){
nhost = gethostbyname(sIp);
if( nhost == NULL ){
//return -2;
AfxMessageBox(TEXT("gethostbyname Error" ) );
WSACleanup( );
return;
}
CopyMemory(&sAddr.sin_addr,nhost->h_addr_list[0],nhost->h_length);
}
rc = connect( nsock , (struct sockaddr *)&sAddr , sizeof( sAddr ) );
if( rc == SOCKET_ERROR ){
AfxMessageBox(TEXT("connect Error" ) );
DWORD x = WSAGetLastError();
CString s;
s.Format(L"LastError=[%d]" , x );
AfxMessageBox( s );
WSACleanup( );
return;
}
.......
closesocket( nsock );
WSACleanup();
AfxMessageBox( L"Connect Ok!" ) ;
以上是我的部分代码,程序在虚拟机中可以运行通过,但是在PPC机上,运行到connect的时候,将报错,出错代码是120,请问一下,这是怎么回事?
|
|