home *** CD-ROM | disk | FTP | other *** search
- /*
- udp test translated into rexx
- from Amiga Magazine n.93 udp.c test by Rudi Chiarito
-
- Usage: udp <host> <port> <localPort>
-
- i.e.:
- shell1 udp localhost 4000 4001
- shell2 udp localhost 4001 4000
-
- to stop push <ctrl-c> in the shells
-
- */
-
- parse arg host remotePort localPort .
-
- if ~show("L","rxsocket.library") then
- if ~addLib("rxsocket.library",0,-30) then do
- say "can't find rxsocket.library"
- exit
- end
-
- if IsDotAddr(host) then do
- remote.addrFamily = "INET"
- remote.addrAddr = host
- end
- else do
- if ~gethostbyname("H",host) then do
- say "udp: host" host "non trovato."
- exit
- end
- remote.addrFamily = h.hostAddrType
- remote.addrAddr = h.hostAddrList.0
- end
-
- remote.addrPort = remotePort
-
- sock = socket("INET","DGRAM","IP")
- if sock<0 then do
- say "udp: non posso aprire il socket:" errno()
- exit
- end
-
- local.addrFamily = "INET"
- local.addrAddr = 0
- local.addrPort = localPort
- if bind(sock,"LOCAL")<0 then do
- say "udp: non posso allocare la porta:" errno()
- exit
- end
-
- call IOCtlSocket(sock,"FIONBIO",1)
-
- data = "Ciao"
- dataLen = length(data)
-
- down = 0
- do while 1
-
- n = SendTo(sock,data,0,"REMOTE")
- if n!=dataLen then do
- say "udp errore di SendTo():" errno()
- exit
- end
-
- call delay(10)
-
- if down then call WriteCh("STDOUT",".")
-
- n = RecvFrom(sock,"BUFF",10,0,"REMOTE")
- if n==-1 then do
- err = errno()
- if err==35 then do
- if ~down then do
- call WriteCh("STDOUT","udp: non ricevo più dati .")
- down = 1
- end
- end
- else do
- say "udp: errore di RecvFrom():" err
- exit
- end
- end
- else do
- say "udp: byte letti:" n
- down = 0
- end
-
- end
-