Program INLtest;

{$i INL.inc }


 Var
	resa,resb,conex,stat : byte;
	IP : LAIP;
	serv:Openstring; 
	letra,letrain:char;
	puerto,code:integer;  

 Begin
    
    PUT_P1[4]:=201;
	Clrscr;
	Write('INL instalado:');
	Writeln(INLinstalado);
	if (inlinstalado=1) then
	begin
		if paramcount=0 then 
		begin         
			write('Servidor:');
			readLN(serv);
			write('Puerto:');
			readLN(puerto);
		end	
		 else
		begin
			serv:=paramstr(1);
			val(paramstr(2),puerto,code);
		end; 
		serv:=serv+chr(0);
		INLDNS_Q(serv);

		repeat
			INLDNS_S(resa,resb,ip[1],ip[2],ip[3],ip[4]);
		until resa>1;
    	writeln(' ');
   		writeln('resultado:',resa,',',resb);

        if resa=2 then
        begin  
             
			writeln('La IP es:',ip[1],',',ip[2],',',ip[3],',',ip[4]);
		
			conex:=inltcp_open(ip[1],ip[2],ip[3],ip[4],puerto,-32768,0);  

			repeat 
			stat:=INLTCP_STATUS (conex);
			write(' '); write(stat);
			until (stat=4) or (stat=0);


			if stat=4 then 
			begin
				writeln('conexion abierta');

				repeat
		    		letra:=chr(0);
					if keypressed then
		  			begin 
		    			letra:=inkey;
		    			write(letra);
			    		if letra=chr(13) then write(chr(10));
			    		inltcp_sendchar(conex,letra);
		    			if letra=chr(13) then
			    			inltcp_sendchar(conex,chr(10));
	 		  		end;   
		  			letrain:=inltcp_rcvchar(conex); 
   	      			if letrain>chr(0) then write(letrain);
				until (letra=chr(27)) or (INLTCP_STATUS (conex)<>4);		      
				inltcp_close(conex);   

				repeat
					stat:=INLTCP_STATUS (conex);
					write(' '); write(stat);
				until (stat=0);
			 end;
		end;	
	end;         

             
    INLterminate;

	
 End.
