TEST.C 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /****************************************************************************
  2. *
  3. * File : test.c
  4. * Date Created : 1/3/95
  5. * Description : sample code for the NetNOW! system
  6. *
  7. * Programmer(s) : Nick Skrepetos
  8. * Last Modification : 3/22/95 - 8:28:16 AM
  9. * Additional Notes :
  10. *
  11. *****************************************************************************
  12. * Copyright (c) 1994, HMI, Inc. All Rights Reserved *
  13. ****************************************************************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include "hmistd.h"
  18. #include "netnow.h"
  19. #include "vdata.h"
  20. #include "vchat.h"
  21. // local functions
  22. VOID hmiNetworkDemo ( VOID );
  23. /****************************************************************************
  24. *
  25. * Syntax
  26. *
  27. * VOID main( WORD wArgc, PSTR szArgv[] )
  28. *
  29. * Description
  30. *
  31. * main function for testing ipx drivers
  32. *
  33. * Parameters
  34. *
  35. * Type Description
  36. * --------------------------
  37. * wArgc Arguement count
  38. * szArgv Arguements
  39. *
  40. * Return
  41. *
  42. * nothing
  43. *
  44. ****************************************************************************/
  45. VOID main( WORD wArgc, PSTR szArgv[] )
  46. {
  47. // read the .ini file
  48. if ( !hmiVCHATInit() )
  49. {
  50. // print error
  51. printf( "ERROR: Could not read NETNOW.INI\n" );
  52. // exit
  53. exit( 1 );
  54. }
  55. // display message
  56. printf( "NetNOW! system initialization started.\n" );
  57. // check if NetNOW! is present
  58. if ( hmiNETNOWInitSystem( 8 ) != _NETNOW_NO_ERROR )
  59. {
  60. // print error
  61. printf( "ERROR: NetNOW! could not locate IPX or NetBIOS!\n" );
  62. // error
  63. exit( 1 );
  64. }
  65. // display
  66. printf( "\nNetNOW! system initialized!\n\n" );
  67. // check for information display
  68. if ( wNETInfoFlag )
  69. switch( hmiNETNOWGetNetworkType() )
  70. {
  71. case _NETNOW_IPX :
  72. // display type
  73. printf( "Network is using a IPX based protocol.\n" );
  74. break;
  75. case _NETNOW_NETBIOS:
  76. // display type
  77. printf( "Network is using a NetBIOS based protocol.\n" );
  78. break;
  79. }
  80. // find nodes
  81. printf( "\nAttempting to Locate %d Nodes.\n", wNETNodes );
  82. // find the requested nodes
  83. if ( hmiNETNOWFindNodes( wNETNodes ) )
  84. printf( "\n\nLocated all requested nodes!\n" );
  85. else
  86. {
  87. printf( "\n\nERROR: could not locate the requested nodes.\n" );
  88. }
  89. // network demo
  90. hmiNetworkDemo();
  91. // uninit system
  92. hmiNETNOWUnInitSystem();
  93. }
  94. /****************************************************************************
  95. *
  96. * Syntax
  97. *
  98. * VOID hmiNetworkDemo( VOID )
  99. *
  100. * Description
  101. *
  102. * simple example of sending messages from one machine to another
  103. *
  104. * Parameters
  105. *
  106. * none
  107. *
  108. * Return
  109. *
  110. * nothing
  111. *
  112. ****************************************************************************/
  113. VOID hmiNetworkDemo( VOID )
  114. {
  115. WORD wExitFlag;
  116. PSTR pPacket;
  117. WORD wActiveNodes;
  118. WORD wConsoleNode;
  119. _XFER_BLOCK_HEADER sBlock;
  120. BYTE szMessage[ 128 ];
  121. // initialize exit flag
  122. wExitFlag = _FALSE;
  123. // get active nodes
  124. wActiveNodes = hmiNETNOWGetActiveNodes();
  125. // get console node
  126. wConsoleNode = hmiNETNOWGetConsoleNode();
  127. // display banner
  128. printf( "\n\n********* NetNOW! Demonstration *********\n\n" );
  129. // display console node
  130. printf( "Number of Active Nodes : %d\n", wActiveNodes );
  131. printf( "Node Number of this Computer : %d\n", wConsoleNode );
  132. // display message
  133. printf( "\n(S)end to station, (Q)uit\n" );
  134. // wait for exit flag
  135. while( !wExitFlag )
  136. {
  137. // check if we have data
  138. if ( hmiNETNOWGetHeader( (PSTR)&sBlock, sizeof( _XFER_BLOCK_HEADER ), &pPacket ) )
  139. {
  140. // check header type
  141. switch( sBlock.wType )
  142. {
  143. case _XFER_BLOCK_DATA :
  144. // get data block
  145. hmiNETNOWGetBlock( pPacket, szMessage, sBlock.wLength );
  146. // print message
  147. printf( "%s\n", szMessage );
  148. break;
  149. }
  150. // post listen
  151. hmiNETNOWPostListen();
  152. }
  153. // check for key press
  154. if ( kbhit() )
  155. switch( tolower( getch() ) )
  156. {
  157. case 's' :
  158. // set up header type
  159. sBlock.wType = _XFER_BLOCK_DATA;
  160. // display
  161. printf( "Enter Message : \n" );
  162. // get message
  163. gets( szMessage );
  164. // set block length
  165. sBlock.wLength = strlen( szMessage ) + 1;
  166. // send data
  167. while( !hmiNETNOWSendData( (PSTR)&sBlock, sizeof( _XFER_BLOCK_HEADER ), (PSTR)szMessage,
  168. sBlock.wLength, wConsoleNode ^ 0x01 ) );
  169. break;
  170. case 'q' :
  171. // set exit flag
  172. wExitFlag = _TRUE;
  173. break;
  174. }
  175. }
  176. }