home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / comms / other / rxsocket / examples / echoudp.rexx < prev    next >
OS/2 REXX Batch file  |  1998-05-09  |  1KB  |  62 lines

  1. /*
  2.     echo udp client - Usage: echoudp <host>
  3. */
  4.  
  5.  
  6. parse arg host .
  7.  
  8. if ~show("L","rxsocket.library") then
  9.     if ~addLib("rxsocket.library",0,-30) then do
  10.         say "can't find rxsocket.library"
  11.         exit
  12.     end
  13.  
  14. if host="" || host="?" then do
  15.     say "Usage: echoudp <host>"
  16.     exit
  17. end
  18.  
  19. addr = resolve(host)
  20. if addr=="-1" then do
  21.     say "echoudp: no host <" || host || ">"
  22.     exit
  23. end
  24.  
  25. if ~GetServByName("SE","echo","udp") then do
  26.     say "echoudp: no echo udp service"
  27.     exit
  28. end
  29.  
  30. remote.addrFamily = "INET"
  31. remote.addrAddr   = addr
  32. remote.addrPort   = se.servPort
  33.  
  34. sock = socket("INET","DGRAM","IP")
  35. if sock<0 then do
  36.     say "echoudp: no socket (" || errno() || ")"
  37.     exit
  38. end
  39.  
  40. local.addrFamily = "INET"
  41. local.addrAddr     = 0
  42. local.addrPort   = 0
  43. if bind(sock,"LOCAL")<0 then do
  44.     say "echoudp: bind error (" || errno() || ")"
  45.     exit
  46. end
  47.  
  48. data = "echo udp service test"
  49. n = SendTo(sock,data,0,"REMOTE")
  50. if n<length(data) then do
  51.     say "echoudp: SendTo error (" || errno() || ")"
  52.     exit
  53. end
  54.  
  55. len = RecvFrom(sock,"BUF",256,0,"REMOTE")
  56. if len<0 then do
  57.     say "echoudp: recvfrom error (" || errno() || ")"
  58.     exit
  59. end
  60. say buf
  61. call CloseSocket(sock)
  62.