home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 60 / supercd60_2.iso / BlitzBasic / Blitz2DPCP / data1.cab / Support / help / commands / 2d_examples / echoclient.bb next >
Encoding:
Text File  |  2001-11-21  |  756 b   |  36 lines

  1.  
  2. AppTitle "Blitz UDP Echo Client"
  3.  
  4. host$=Input$( "Host:" )
  5. If host$="" Then End
  6. If Not CountHostIPs( host$ ) RuntimeError "host not found"
  7. host_ip=HostIP(1)
  8.  
  9. UDPTimeouts 5000
  10.  
  11. udp=CreateUDPStream()
  12. If Not udp RuntimeError "CreateUDPStream failed"
  13.  
  14. Print "Echo Client - "+DottedIP$( UDPStreamIP( udp ) )+":"+UDPStreamPort( udp )
  15.  
  16. Repeat
  17.     msg$=Input$( "Message to echo:" )
  18.     
  19.     WriteLine udp,msg$
  20.     WriteInt udp,MilliSecs()
  21.     SendUDPMsg udp,host_ip,7
  22.     
  23.     If Eof( udp )<0 RuntimeError "SendUDPMsg failed"
  24.     
  25.     ip=RecvUDPMsg( udp )
  26.     If Eof( udp )<0 RuntimeError "RecvUDPMsg failed"
  27.     
  28.     If ip
  29.         t=MilliSecs()
  30.         reply$=ReadLine$( udp )
  31.         ms=t-ReadInt( udp )
  32.         Print "Reply: "+reply$+" ("+ms+"ms)"
  33.     Else
  34.         Print "Timeout"
  35.     EndIf
  36. Forever