home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / QBWNET10.ZIP / CHAT.BAS next >
BASIC Source File  |  1993-06-23  |  6KB  |  197 lines

  1. '
  2. '
  3. '  CHAT.BAS - Sample Chat program written using Network Datagram Services
  4. '
  5. '    This program uses QBWARE/Net, the Network Communications Library for
  6. '    Basic and Quickbasic from AJM Software.  It is a simple chat program
  7. '    that demonstrates the basic concepts of peer-to-peer communications.
  8. '
  9. '    Copyright (C) - AJM SOftware, 1993
  10. '
  11. '
  12. '
  13. '
  14. '    NETWORK.BI contains FUNCTION prototypes and TYPE declarations needed by
  15. '        the library.
  16. '
  17.         REM $INCLUDE: 'network.bi'
  18.  
  19. '
  20. '    Misc TYPE statement for scrolling a portion of the screen
  21. '
  22.         TYPE RegType
  23.              ax    AS INTEGER
  24.              bx    AS INTEGER
  25.              cx    AS INTEGER
  26.              dx    AS INTEGER
  27.              si    AS INTEGER
  28.              di    AS INTEGER
  29.              flags AS INTEGER
  30.         END TYPE
  31.  
  32. '
  33. '    These TYPE's are found in NETWORK.BI
  34. '
  35.         DIM MyStation AS NetStation
  36.         DIM YourStation AS NetStation
  37.         DIM MsgOut AS NetMsg
  38.         DIM MsgIn AS NetMsg
  39.  
  40. '
  41. '    These values define the window used to display incoming messages.
  42. '
  43.         Tr = 5: Lc = 1: Br = 25: Rc = 80
  44.         SFg = 7 : SBg = 0
  45.  
  46. '
  47. '    These values are used by the ***VERY*** basic keyboard handler.
  48. '
  49.         BkSpace$ = CHR$(8)
  50.         Enter$ = CHR$(13)
  51.         Esc$ = CHR$(27)
  52.  
  53. '
  54. '    Program startup
  55. '
  56.         CLS
  57.         LOCATE 1, 30
  58.         PRINT "Network Chat Utility"
  59.  
  60.         LOCATE 4, 1
  61.         WHILE LEN(MyName$) = 0 OR LEN(MyName$) > 8
  62.                 INPUT ;"Enter your Name (8 chars max): ", MyName$
  63.         WEND
  64.         MyName$ = LEFT$(LTRIM$(RTRIM$(MyName$)) + ":" + SPACE$(8), 10)
  65.  
  66.         LOCATE 4, 1
  67.         PRINT SPACE$(79);
  68.  
  69. '
  70. '    Initialize the Network Communications Library
  71. '
  72.         GOSUB NetWorkStartUp
  73.  
  74. '
  75. '    Send a message indicating that I'm signing on.
  76. '
  77.         MsgOut.Text = MyName$ + "Logging In........." + DATE$ + SPACE$(2) + TIME$
  78.         Rc = NetBroadcast(NetHandle&, MsgOut)
  79.  
  80.         LOCATE 3, 1
  81.         PRINT "Msg:"
  82.         InKy$ = ""
  83.  
  84. '
  85. '    This is the mainline loop.   It polls the keyboard as well as the Network
  86. '        Communication buffers looking for leyboard input or Network traffic.
  87. '
  88.         WHILE InKy$ <> Esc$        'loop until [Esc] is pressed
  89.                 InKy$ = INKEY$
  90.                 IF InKy$ <> "" THEN GOSUB ProcessInp
  91.                 Rc = NetReceive(YourStation, MsgIn)
  92.                 IF Rc = 0 THEN GOSUB ProcessMsgIn
  93.                 LOCATE 1,69: PRINT DATE$;
  94.                 LOCATE 2,69: PRINT TIME$;
  95.         WEND
  96.  
  97.         MsgOut.Text = MyName$ + "Logging Out......... " + DATE$ + SPACE$(2) + TIME$
  98.         Rc = NetBroadcast(NetHandle&, MsgOut)
  99.         END
  100.  
  101.  
  102. '
  103. '    This procedure allocates storage needed by the communication library and
  104. '        initializes all network control blocks.  If the Network software
  105. '        is not loaded, the startup routines return a -1 and this program
  106. '        is terminated.
  107. '
  108. NetWorkStartUp:
  109.  
  110.         Rc = NetStart(MyStation)
  111.         IF Rc <> 0 THEN
  112.                 CLS
  113.                 PRINT "Network not detected .........."
  114.                 PRINT "Program Ending .........."
  115.         END IF
  116. '
  117. '    Issue 5 listen requests for incoming messages.  This allows you to
  118. '        receive up to 5 messages at the same instant.
  119. '
  120.         NetHandle& = NetListen&
  121.         NetHandle& = NetListen&
  122.         NetHandle& = NetListen&
  123.         NetHandle& = NetListen&
  124.         NetHandle& = NetListen&
  125.         RETURN
  126.  
  127. '
  128. '    This is a short routine to handle the keyboard and display the
  129. '        appropriate letter on screen.  Please note that BackSpace is
  130. '        the only edit key.  [Escape] terminates the program.
  131. '
  132. ProcessInp:
  133.  
  134.         SELECT CASE InKy$
  135.  
  136.                 CASE Esc$               'Shut down program
  137.                         RETURN
  138.  
  139.                 CASE BkSpace$           'backup
  140.                         IF Len(Text$) > 1 THEN Text$ = LEFT$(Text$, LEN(Text$) - 1)
  141.  
  142.                 CASE Enter$             'Send the message
  143.                         GOSUB SendText
  144.  
  145.                 CASE ELSE               'filter out extended (i.e. F1-F12)
  146.                         IF LEN(InKy$) = 1 THEN Text$ = Text$ + InKy$
  147.         END SELECT
  148.  
  149.         LOCATE 3, 6
  150.         PRINT LEFT$(Text$ + SPACE$(69), 69);
  151.         IF LEN(Text$) > 69 THEN GOSUB SendText  'Automatically Send Msg
  152.         RETURN
  153.  
  154. '
  155. '    This routine sends a message to all stations using the Network Datagram
  156. '        services.
  157. '
  158. SendText:
  159.  
  160.         MsgOut.Text = MyName$ + Text$
  161.         Rc = NetBroadcast(NetHandle&, MsgOut)
  162.         MsgIn.Text = MsgOut.Text
  163.         GOSUB ProcessMsgIn
  164.         Text$ = ""
  165.         RETURN
  166.  
  167. '
  168. '    This routine scrolls the CHAT window and places the new message on the
  169. '        bottom of the screen.  Note that we assume the new message will
  170. '        fit on one line.  If the doesn't, the entire screen will scroll
  171. '        in a very unprofessional manner.
  172. '
  173. ProcessMsgIn:
  174.  
  175.         Tr = 5: Lc = 1: Br = 25: Rc = 80
  176.         SFg = 7 : SBg = 0
  177.         CALL WScroll (Tr, Br, Lc, Rc, SFg, SBg)
  178.         TextIn$ = RTRIM$(MsgIn.Text)
  179.         LOCATE 25,1
  180.         PRINT TextIn$;
  181.         RETURN
  182.  
  183.  
  184.  
  185. SUB WScroll (Tr, Br, Lc, Rc, SFg, SBg)
  186.  
  187. '    This is a short routine to scroll a portion of the screen.
  188. '
  189.     DIM regs AS RegType
  190.  
  191.         regs.ax = &H601
  192.         regs.bx = SBg
  193.         regs.cx = ((Tr - 1) * 256) + (Lc - 1)
  194.         regs.dx = ((Br - 1) * 256) + (Rc - 1)
  195.         CALL ExecInt(&H10, SEG regs)
  196. END SUB
  197.