home *** CD-ROM | disk | FTP | other *** search
- /*
- Mix protocols echo client.
- Shows the usage of OpenConnection().
- Just a simple echo client, but it wants as second argument
- the string "tcp" or "udp".
- To try this on localhost be sure your echo/tcp and echo/udp
- services are enabled in the inetd database.
- Then just write
- - rx echomix localhost tcp
- - rx echomix localhost udp
- */
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
-
- prg = ProgramName("NOEXT")
-
- if ~RMH_ReadArgs("HOST/A,PROTO/A") then do
- call PrintFault(IoErr(),prg)
- exit
- end
- if parm.1.value~="tcp" & parm.1.value~="udp" then call err "PROTO must be 'tcp' or 'udp'"
-
- sock=OpenConnection(parm.1.value,"echo",parm.0.value)
- if sock<0 then
- select
- when sock==-5 then call err "echomix: can't bind socket on port."
- when sock==-4 then call err "echomix: service echo not found."
- when sock==-3 then call err "echomix: service not found."
- when sock==-2 then call err "echomix: host <" || parm.0.value || "> not found."
- when sock==-1 then call "echomix: unable to connect <"parm.0.value":echo> (" || errno() || ")"
- end
-
- request="echo service test"
- if send(sock,request)~=length(REQUEST) then
- call err "echomix: send error (" || errno() || ")"
-
- len=recv(sock,"BUF",256)
- if len<0 then call err "echomix: recv error (" || errno() || ")"
-
- say buf
- call CloseSocket(sock)
- exit
-
- err:
- parse arg msg
- say prg":" msg
- exit