/* echo tcp client - Usage: echotcp */ parse arg host . if ~show("L","rxsocket.library") then if ~addLib("rxsocket.library",0,-30) then do say "can't find rxsocket.library" exit end if host="" || host="?" then do say "Usage: echotcp " exit end addr = resolve(host) if addr=="-1" then do say "echotcp: no host <" || host || ">" exit end if ~getservbyname("SE","echo","tcp") then do say "echotcp: echo tcp service not found" exit end sin.ADDRFAMILY = "INET" sin.ADDRADDR = addr sin.ADDRPORT = SE.SERVPORT sock = socket("INET","STREAM","IP") if sock<0 then do say "echotcp: no socket (" || errno() || ")" exit end if connect(sock,"SIN")<0 then do say "echotcp: connect error (" || errno() || ")" exit end REQUEST = "echo service test" res = send(sock,REQUEST,x2d(100)) if res~=length(REQUEST) then do say "echotcp: send error (" || errno() || ")" exit end len = recv(sock,"BUF",256,x2d(100)) if len<0 then do say "echotcp: recv error (" || errno() || ")" exit end say buf call CloseSocket(sock)