{The SERVER program must be run first. Otherwise a NET_CONNECT() error 20 will result. This is a simple chat program. The hchat program must be compiled with the ip address of the host running the schat program.} program host; uses pctcp,crt; var d:word; as:addr; e:word; sa,aa:word; w,temp:word; buffer:array[1..100] of char; dat:char; done:boolean; begin if not pctcp_installed then begin writeln('PCTCP not installed'); halt; end; as.IP_addr.a := 149; {Assign values for server address} as.IP_addr.b := 160; {If the server address is unknown, the client} as.IP_addr.c := 18; {must look it up in the DNS with NM_RES_NAME()} as.IP_addr.d := 16; as.remote_socket := $6666; {Well known port for connection to server} as.local_socket := $0000; {Force automatic allocation of local port} as.protocol := protocol_stream; {Specify TCP as protocol} writeln('Attempting to connect'); d:=$ffff; {Force automatic allocation of descriptor} net_connect(d,protocol_stream,as,e); if e<>0 then begin writeln('net_connect:',e); halt; end; done:=false; dat := ' '; while (not done)and (dat <> 'Z') do begin sa:=seg(buffer); aa:=ofs(buffer); {Set up pointers to buffer} if keypressed then begin dat := readkey; buffer[1]:=dat; net_write(d,1,0,sa,aa,w,e); if e <> 0 then begin writeln('net_write:',e); done:=true; end else write(dat); end; net_read(d,100,no_block,sa,aa,as,w,e); if e=0 then for temp := 1 to w do write(buffer[temp]) else if e<>net_err_wouldblock then done:=true; end; net_eof(d,e); {Close transmition side of connection} writeln('net_eof:',tcp_error[e]); if e<>0 then halt; net_release(d,e); {Release descriptor} writeln('net_release:',e); if e<>0 then halt; writeln('Done.'); end.