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

  1. /*
  2.     echo tcp client - Usage: echotcp <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: echotcp <host>"
  16.     exit
  17. end
  18.  
  19. addr = resolve(host)
  20. if addr=="-1" then do
  21.     say "echotcp: no host <" || host || ">"
  22.     exit
  23. end
  24.  
  25. if ~getservbyname("SE","echo","tcp") then do
  26.     say "echotcp: echo tcp service not found"
  27.     exit
  28. end
  29.  
  30. sin.ADDRFAMILY = "INET"
  31. sin.ADDRADDR   = addr
  32. sin.ADDRPORT   = SE.SERVPORT
  33.  
  34. sock = socket("INET","STREAM","IP")
  35. if sock<0 then do
  36.     say "echotcp: no socket (" || errno() || ")"
  37.     exit
  38. end
  39.  
  40. if connect(sock,"SIN")<0 then do
  41.     say "echotcp: connect error (" || errno() || ")"
  42.     exit
  43. end
  44.  
  45. REQUEST = "echo service test"
  46. res = send(sock,REQUEST,x2d(100))
  47. if res~=length(REQUEST) then do
  48.     say "echotcp: send error (" || errno() || ")"
  49.     exit
  50. end
  51.  
  52. len = recv(sock,"BUF",256,x2d(100))
  53. if len<0 then do
  54.     say "echotcp: recv error (" || errno() || ")"
  55.     exit
  56. end
  57. say buf
  58. call CloseSocket(sock)
  59.