home *** CD-ROM | disk | FTP | other *** search
- /*
- A simple stand alone service example.
- It waits for connections on port 4000.
- After a connection is made,
- it waits for a string of max 256 char len and send it back reversed.
- To stop it:
-
- rx "shell 'REVSERVPORT' 'QUIT'"
-
- */
-
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
-
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
-
-
- if ~Open("STDERR","*","W") | ~OpenPort("REVSERVPORT") then exit
-
- sock = socket("INET","STREAM","IP")
- if sock<0 then do
- say "Non posso aprire il socket:" errno()
- exit
- end
-
- local.ADDRFAMILY = "INET"
- local.ADDRADDR = 0
- local.ADDRPORT = 4000
- if bind(sock,"LOCAL")<0 then do
- say "Non posso allocare la porta:" errno()
- exit
- end
-
- sig = 2**PortSignal("REVSERVPORT")
- SEL.READ.0=sock
- open = 1
- do while open
-
- if Listen(sock,5)<0 then do
- say "Errore Listen():" errno()
- exit
- end
-
- res = WaitSelect("SEL",,,sig)
-
- pkt = GetPkt("REVSERVPORT")
- if pkt ~= null() then do
- comm= GetArg(pkt)
- call reply(pkt)
- if upper(comm) == "QUIT" then open = 0
- end
-
- if sel.0.read then do
-
- lsock = accept(sock,"REMOTE")
- if lsock<0 then do
- say "Errore accept:" errno()
- exit
- end
-
- auth = AuthFun(remote.addrAddr,4000,remote.addrPort)
- say auth
-
- len = recv(lsock,"BUF",256)
- if ( len > 0 ) then do
- buf = reverse(buf)
- if send(lsock,buf) ~= length(buf) then do
- say "send: error" errno())
- end
- end
- if ( len < 0 ) & ( errno() ~= 35 )
- then call say "recv: error" errno()
-
- call CloseSocket(lsock)
-
- end
-
- end
-
- exit
-