如何用IPX协议进行通信,而不是TCPIP?

wjh1014 2002-12-22 01:51:26
最后有源码!
...全文
134 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
invalid 2002-12-22
  • 打赏
  • 举报
回复
给你发邮件了。太长了,粘不下!
invalid 2002-12-22
  • 打赏
  • 举报
回复
给你篇代码看看吧
// Module Name: sockspx.c
//
// Description:
// This sample illustrates using IPX/SPXII client and
// servers. The server is very simple and can only handle
// one client connection at a time.
//
// Compile:
// cl sockspx.c ws2_32.lib
//
// Command Line Parameters/Options:
// sockspx.c -s -c -n:IPX-Addr -e:Socket -l:IPX-Addr -p:[d|s|p]
// -m -b:bytes -r:num
// -s Act as server
// -c Act as client
// -n:IPX-Addr Servers IPX addr (AABBCCDD.AABBCCDDEEFF)
// -e:Socket Socket enpoint server is listening on
// -l:IPX-Addr Local IPX address
// -p:[d|s|p] Protocol to use
// d Datagram (IPX)
// s Stream (SPXII)
// p Seq Packet (SPXII)
// -m Enumerate local IPX addresses
// -b:Bytes Number of bytes to send
// -r:Num How many sends to perform (client only)
//
// To run the application as a server, the following command
// line can be specified:
//
// sockspx -s -e:8000 -p:s
//
// To run the application to act as a client, the following
// command line can be specified:
//
// sockspx -c -n AABBCCDD.AABBCCDDEEFF -e 8000 -p s
//
// To enumerate the local IPX adapters, the following command
// line will have to be specified:
//
// sockspx -m
//

#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <stdlib.h>

#include <wsipx.h>
#include <wsnwlink.h>

#define MAX_DATA_LEN 64000


//
// Global Variables
//

BOOL bServer = TRUE, // client or server
bEnumerate = FALSE; // enumerate addresses

SOCKET sock = INVALID_SOCKET,
newsock = INVALID_SOCKET;
char *pszServerAddress, // Server's IPX address string
*pszLocalAddress, // Local IPX address string
*pszServerEndpoint, // Server's endpoint (socket) string
chProtocol = 's'; // Protocol
DWORD dwNumBytes=512, // Number of bytes to send
dwNumToSend=5; // Number of times to send

//
// Function: CreateSocket
//
// Description:
// Create a socket based upon the command line parameters. This
// creates the main socket (i.e. the listening socket for the
// server and the connecting socket for the client).
// SPX sockets use either SOCK_STREAM or SOCK_SEQPACKET but must
// be of the protocol NSPROTO_SPX or NSPROTO_SPXII.
// IPX sockets must use SOCK_DGRAM and NSPROTO_IPX.
//
void CreateSocket()
{
int proto,
sockettype;

// Find out the socket type
//
if (chProtocol == 'd')
sockettype = SOCK_DGRAM;
else if (chProtocol == 's')
sockettype = SOCK_STREAM;
else
sockettype = SOCK_SEQPACKET;
//
// Get the protocol
//
if (chProtocol == 'd')
proto = NSPROTO_IPX;
else
proto = NSPROTO_SPX;

sock = socket(AF_IPX, sockettype, proto);
if (sock == INVALID_SOCKET)
{
printf("socket() failed: %d\n", WSAGetLastError());
return;
}
return;
}

//
// Function: usage
//
// Description:
// Print the usae information.
//
void usage(char *progname)
{
printf("usage: %s [-s|-c] -e:Socket -n:ServerAddr \
-l:LocalAddr -p:[d|s|p] -m -b:bytes\n", progname );
printf("\t -s Act as server (default)\n");
printf("\t -c Act as client\n");
printf("\t -e:Socket Server's socket (port)\n" );
printf("\t -n:Addr Server's IPX Address\n" );
printf("\t -l:Addr Local IPX Address\n" );
printf("\t -p:d|s|p Protocol type\n");
printf("\t d datagram (IPX)\n");
printf("\t s stream (SPXII)\n");
printf("\t p sequenced packet (SPXII)\n");
printf("\t -m Enumerate Local Addresses\n");
printf("\t -b:int Number of bytes to send\n");
printf("\t -r:num Number of repitions to send\n");

ExitProcess(-1);
}

//
// Function: PrintIpxAddress
//
// Description:
// This function prints out an IPX address in human readable
// form.
//
void PrintIpxAddress(char *lpsNetnum, char *lpsNodenum)
{
int i;

// Print the network number first
//
for (i=0; i < 4 ;i++)
{
printf("%02X", (UCHAR)lpsNetnum[i]);
}
printf(".");
//
// Print the node number
//
for (i=0; i < 6 ;i++)
{
printf("%02X", (UCHAR) lpsNodenum[i]);
}
printf("\n");

return;
}

//
// Function: BtoH
//
// Description:
// BtoH () returns the equivalent binary value for an individual
// character specified in the ascii format.
//
UCHAR BtoH(char ch)
{
if ((ch >= '0') && (ch <= '9'))
{
return (ch - '0');
}
if ((ch >= 'A') && (ch <= 'F'))
{
return (ch - 'A' + 0xA);
}
if ((ch >= 'a') && (ch <= 'f'))
{
return (ch - 'a' + 0xA);
}
//
// Illegal values in the IPX address will not be accepted
//
printf("Illegal characters in IPX address!\n");

ExitProcess(-1);
}

//
// Function: AtoH
//
// Description:
// AtoH () coverts the IPX address specified in the string
// (ascii) format to the binary (hexadecimal) format.
//
void AtoH(char *szDest, char *szSource, int iCount)
{
while (iCount--)
{
*szDest++ = (BtoH(*szSource++) << 4) + BtoH(*szSource++);
}
return;
}


//
// Function: FillIpxAddress
//
// Description:
// FillIpxAddress() fills a structure of type SOCKADDR_IPX
// with relevant address-family, network number, node number
// and socket (endpoint) parameters.
//
void FillIpxAddress(SOCKADDR_IPX *psa, LPSTR lpsAddress, LPSTR lpsEndpoint)
{
LPSTR pszPoint;

ZeroMemory(psa, sizeof(SOCKADDR_IPX));

psa->sa_family = AF_IPX;
//
// Check if an address is specified
//
if (lpsAddress != NULL)
{
//
// Get the offset for node number/network number separator
//
pszPoint = strchr(lpsAddress, '.');

if (pszPoint == NULL)
{
printf("IPX address does not have a separator\n");
ExitProcess(-1);
}
// convert the address in the string format to binary format
//
AtoH((CHAR *)psa->sa_netnum, lpsAddress, 4);
AtoH((CHAR *)psa->sa_nodenum, pszPoint + 1, 6);
}
if (lpsEndpoint != NULL)
{
psa->sa_socket = (USHORT)atoi(lpsEndpoint);
}
return;
}

//
// Function: BindSocket
//
// Description:
// BindSocket() binds the global socket descriptor 'sock' to
// the specified address. If an endpoint is specified it uses
// that or it binds to a system assigned port.
//
void BindSocket(SOCKADDR_IPX *psa, LPSTR lpsAddress, LPSTR lpsEndpoint)
{
int ret;

// Fill the givenSOCKADDR_IPX structure
//
FillIpxAddress(psa, lpsAddress, lpsEndpoint);

ret = bind(sock, (SOCKADDR *) psa, sizeof (SOCKADDR_IPX));
if (ret == SOCKET_ERROR)
{
printf("bind() failed: %d\n", WSAGetLastError());
return;
}
// Print the address we are bound to. If a particular interface is not
// mentioned in the BindSocket() call, this may print the address as
// 00000000.0000000000000000. This is because of the fact that an
// interface is picked only when the actual connection establishment
// occurs, in case of connection oriented socket.
//
printf("Bound to Local Address - " );
PrintIpxAddress(psa->sa_netnum, psa->sa_nodenum);

return;
}

invalid 2002-12-22
  • 打赏
  • 举报
回复
不是我要灌水啊,是发了后提示500错误。重新发送,还是提示,最后成功了。可是贴了三遍。
lj_csdn 2002-12-22
  • 打赏
  • 举报
回复
socket()参数里指定为IPX/SPX类型就行。名字忘了。
参考win32 sdk的winsocket2编程
invalid 2002-12-22
  • 打赏
  • 举报
回复
嘿嘿,UP!
invalid 2002-12-22
  • 打赏
  • 举报
回复
嘿嘿,UP!
invalid 2002-12-22
  • 打赏
  • 举报
回复
嘿嘿,UP。

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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