熬夜..还没有解决..大虾来帮帮忙~(IPX协议通信问题)

prefish 2005-10-04 03:39:18
用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();
}
测试到这 一直无法连接
...全文
135 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
prefish 2005-10-06
  • 打赏
  • 举报
回复
谢谢楼上2位..代码我已经解决了..
是network addr和node addr填充错位了,
还有就是在写入结构的时候又把结构给memset了~

鄙视自己一个~:)
elssann 2005-10-06
  • 打赏
  • 举报
回复
http://www.cetinet.com/article/list.asp?indexid=1919
http://www.bytemen.net/dev/html/359.htm
winnuke 2005-10-06
  • 打赏
  • 举报
回复
SOCKADDR_IPX Saddr;
这个结构填充有误?偶也只是猜想罢了,错误类型10051:网络不可抵达,没有已知的路由到达目标主机,你试着在代码中添加下打印目标地址的语句,看看是否为你所想要的目标地址.
prefish 2005-10-04
  • 打赏
  • 举报
回复
谢谢大虾不厌其烦的看,我谢先了~~!!
prefish 2005-10-04
  • 打赏
  • 举报
回复
以下是服务器:
//this is server part.

#include <stdio.h>
#include <windows.h>
#include <winsock.h>
#include <wsipx.h>
#include <wsnwlink.h>
#include <iostream.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.
}
}

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 main()
{
int S_socket, err,C_socket;
int n,m;
SOCKADDR_IPX Saddr;
char *str="Hello world!\0";
char *szXferBuffer="2FFF";
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);


err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )

{
cout<<"error!"<<endl;
return;
}
S_socket=socket(AF_IPX,SOCK_SEQPACKET, NSPROTO_SPX);
memset(&Saddr,0,sizeof(Saddr));
Saddr.sa_family=AF_IPX;

AtoH(szXferBuffer, (char *)&Saddr.sa_socket, 2);

//Saddr.sa_socket=htons(12345);
//Saddr.sin_addr.s_addr=htons(INADDR_ANY);




if(S_socket<0)
cout<<"failed"<<endl;

n=bind(S_socket,(PSOCKADDR)&Saddr,sizeof(SOCKADDR_IPX));
if(n<0)
cout<<"!!!"<<endl;
m=listen(S_socket,10);
if(m<0)
cout<<"***"<<endl;

while(1)
{
C_socket=accept(S_socket,0,0);

send(C_socket,str,sizeof(str),MSG_OOB);
cout<<"send succeff!"<<endl;
break;
}
WSACleanup();

}

18,357

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧