📄 chat.c
字号:
/*============================================================================*/
/* Demo program that illustrates the use of IPX routines for transmitting */
/* data across a network. This program allows a network-wide 'chat' to occur */
/* by any and all users running this program. The chat conversation appears */
/* in the top region of the screen. Each user is requested for a name or */
/* 'handle' for them to be identified. Messages are typed at the foot of the */
/* screen and transmitted across the network to all other users (including */
/* yourself!) when you press the ENTER key. Coool stuff! */
/* */
/* NB: The idea behind this demo was to illustrate the IPX routines. As for */
/* the other code, it isn't guaranteed to be efficient. In fact, to try */
/* and ensure compatability with most compilers I've done things the 'easy' */
/* way which, as we know, isn't usually the best ;-) By all means take the */
/* code and mod it if you feel the need to. */
/*============================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <dos.h>
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned char BOOL;
#define TRUE 1
#define FALSE 0
#define MY_SOCKET 0x869c
#include "ripx.h"
IPX_LOCAL_ADDRESS myAddr;
#define MAX_LEN 80
/* Our IPX Packet definition. It looks a little strange 'cos the header */
/* appears after the Event Control Block. This is okay though since the */
/* ECB is NOT actually transmitted across the network - only the header */
/* and the rest of our packet are. The ECB is only to interface with the */
/* IPX driver. If you use this code and replace the definition of PACKET */
/* with one of your own make sure that szString[] member is the one that */
/* is replaced and that it is in the same order as below. */
#pragma pack(1)
typedef struct tagPACKET
{
IPX_ECB ecb;
IPX_HEADER ipx;
char szString[MAX_LEN];
} PACKET;
#pragma pack()
PACKET Tx, Rx;
void DoChat( WORD wSocket );
void main( void )
{
int nResult;
WORD wSocket;
if ( !IPX_Available() )
{
printf( "IPX not set up/available!\n" );
exit( 1 );
}
/* What's this node's address? */
if ( IPX_GetLocalAddr(&myAddr) )
{
printf( "\n\nDiagnostic Info:\n\n" );
printf( "net Address = %04lX\n",myAddr.netAddr.dwAddr );
printf( "node Address = %02X:%02X:%02X:%02X:%02X:%02X\n",
(unsigned int)myAddr.nodeAddr.cbAddr[0],
(unsigned int)myAddr.nodeAddr.cbAddr[1],
(unsigned int)myAddr.nodeAddr.cbAddr[2],
(unsigned int)myAddr.nodeAddr.cbAddr[3],
(unsigned int)myAddr.nodeAddr.cbAddr[4],
(unsigned int)myAddr.nodeAddr.cbAddr[5] );
}
else
{
printf( "IPX error getting local address!\n" );
}
/* Try to open socket first */
wSocket=IPX_OpenSocket(FALSE,MY_SOCKET);
if ( wSocket!=0xffff )
{
if ( !IPX_InitSendPacket(&Tx.ipx,&Tx.ecb,wSocket,sizeof(Tx.szString)) )
{
printf( "InitSendPacket failed!\n" );
}
if ( !IPX_InitReceivePacket(&Rx.ipx,&Rx.ecb,wSocket,sizeof(Rx.szString)) )
{
printf( "InitReceivePacket failed!\n" );
}
DoChat( wSocket );
if ( !IPX_CloseSocket(wSocket) )
{
printf( "\n\nSocket close failed! Error=%04X\n",IPX_GetLastError() );
}
else
{
printf( "\n\nSocket closed okay!\n" );
printf( "Demo coded by CyberFrog 8:)\n\n" );
}
}
else
{
printf( "Error opening socket. Error=%04X\n",IPX_GetLastError() );
}
}
int Inkey( void )
{
/* Gets a key from system but only if there's one there... */
int key=0;
if ( kbhit() )
{
key=getch();
if ( key==0 ) key=getch()+256;
}
}
void SetPos( int x, int y )
{
/* Sets the position of the cursor on screen using BIOS */
union REGS regs;
regs.h.ah = 0x02;
regs.h.bh = 0x00;
regs.h.dl = (unsigned char)x;
regs.h.dh = (unsigned char)y;
int86( 0x10,®s,®s );
}
void ClearTop( void )
{
/* Clears the top 23 lines of the display */
int i;
for ( i=0; i<23; i++ )
{
SetPos(0,i);
printf( " " );
}
}
void DrawScreen( void )
{
/* Does just what it says on the tin... */
ClearTop();
SetPos( 0,23 );
printf( "哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -