MODULE RFC865Client;
IMPORT
Commands, IP, DNS, TCP, Streams;
CONST QuotePort = 17;
PROCEDURE GetQuote*(context : Commands.Context);
VAR
connection : TCP.Connection;
serverName : ARRAY 32 OF CHAR;
line : ARRAY 513 OF CHAR;
serverIP: IP.Adr;
res : LONGINT;
reader : Streams.Reader;
BEGIN
context.arg.SkipWhitespace; context.arg.String(serverName);
DNS.HostByName(serverName, serverIP, res);
IF res # 0 THEN
context.error.String("Host not found."); context.error.Ln;
RETURN
END;
IP.AdrToStr(serverIP, line);
context.out.String("Server found at "); context.out.String(line); context.out.Ln;
NEW(connection);
connection.Open(TCP.NilPort, serverIP, QuotePort, res);
IF res # 0 THEN
context.error.String("Could not connect to host."); context.error.Ln;
RETURN
END;
Streams.OpenReader(reader, connection.Receive);
REPEAT
reader.Ln(line);
context.out.String(line); context.out.Ln
UNTIL reader.res # 0;
connection.Close;
END GetQuote;
END RFC865Client.
System.Free RFC865Client ~
System.OpenKernelLog
Aos.Call RFC865Client.GetQuote bluebottle.ethz.ch ~