熬夜..还没有解决..大虾来帮帮忙~(IPX协议通信问题)
用winsocks写代码实现局域网的通信,,但是两台机子却怎么也连接不起来(error 10051)
是不是写的有问题呢? 大虾们帮忙看看:
client:
#include <iostream.h>
#include <windows.h>
#include <winsock.h>
#include <wsipx.h>
#include <wsnwlink.h>
#include <stdio.h>
extern unsigned char BtoH(char);
void AtoH(char * src, char * dest, int destlen)
{
char * srcptr;
srcptr = src;
while(destlen--)
{
*dest = BtoH(*srcptr++) << 4; // Put 1st ascii byte in upper nibble.
*dest++ += BtoH(*srcptr++); // Add 2nd ascii byte to above.
}
cout<<"!!!!!!!!!!!"<<dest<<endl;
}
unsigned char BtoH(char ch)
{
if (ch >= '0' && ch <= '9') return (ch - '0'); // Handle numerals
if (ch >= 'A' && ch <= 'F') return (ch - 'A' + 0xA); // Handle capitol hex digits
if (ch >= 'a' && ch <= 'f') return (ch - 'a' + 0xA); // Handle small hex digits
return(255);
}
void PrintIpxAddress(char *lpsNetnum,char *lpsNodenum)
{
int i;
for ( i = 0; i < 4; i++ )
{
fprintf ( stdout, "%02X", (unsigned char) lpsNetnum[i] );
}
fprintf ( stdout, "." );
for ( i = 0; i < 6; i++ )
{
fprintf( stdout, "%02X", (unsigned char) lpsNodenum[i] );
}
fprintf( stdout, "\n" );
}
void main()
{
int S_socket;
SOCKADDR_IPX Saddr;
char *buf="hello!";
char *MAC_addr="00E04CE5168E";
char *network_addr="00000000";
char *socketPort="2FFF";
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int err;
int flag;
AtoH(MAC_addr, (char *)&Saddr.sa_netnum, 4);
//cout<<(char *)&Saddr.sa_netnum;
AtoH(network_addr, (char *)&Saddr.sa_nodenum, 6);
AtoH(socketPort,(char *)&Saddr.sa_socket,2);
err = WSAStartup(wVersionRequested, &wsaData );
if ( err == SOCKET_ERROR )
{
cout<<"WSAStartup failed!"<<endl;
return;
}
memset(&Saddr,0,sizeof(Saddr));
Saddr.sa_family=AF_IPX;
S_socket=socket(AF_IPX,SOCK_SEQPACKET, NSPROTO_SPX);
if(S_socket < 0)
cout<<"creat socket error!"<<endl;
flag=connect(S_socket,(PSOCKADDR)&Saddr,sizeof(Saddr));
if(flag==SOCKET_ERROR)
cout<<"Connetion error! Error at:"<<WSAGetLastError()<<endl;
else
cout<<"Connetion success!"<<endl;
//j=recv(S_socket,buf,1024,MSG_OOB);
//if(j<0) cout<<"Error"<<endl;
//else cout<<"Hello world!\n"<<buf;
// closesocket(S_socket);
// WSACleanup();
}
测试到这 一直无法连接