tw0966.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. { %INTERACTIVE }
  2. { %TARGET=win32,linux }
  3. { Source provided for Free Pascal Bug Report 966 }
  4. {$i-}
  5. uses
  6. {$ifdef Unix}
  7. linux,
  8. {$else}
  9. crt,
  10. {$endif}
  11. Sockets;
  12. Var
  13. S : Longint ; Sin,Sout: Text;
  14. Temp, Temp2 : Char;
  15. i : longint;
  16. const
  17. isocket: TInetSockAddr= (
  18. Family:AF_INET;
  19. Port:$1500;
  20. Addr:((93*256+36)*256+161)*256+130);
  21. {*** ftp 130.161.36.93 i.e. ftp.freepascal.org }
  22. { FIXME: it would be much better to have the number
  23. through a name server but I don't know how to do this ! PM }
  24. procedure perror(const S: string);
  25. begin
  26. writeln(S,SocketError);
  27. halt(100) ;
  28. end;
  29. procedure read_to_eof;
  30. var
  31. temp2 : char;
  32. begin
  33. {$ifdef Unix}
  34. while selecttext(sin,1)>0 do
  35. begin
  36. read(Sin,Temp2);
  37. write(Temp2);
  38. end;
  39. {$else}
  40. repeat until not eof(sin);
  41. while not eof(sin) do
  42. begin
  43. read(Sin,Temp2);
  44. write(Temp2);
  45. delay(1);
  46. end;
  47. {$endif}
  48. end;
  49. begin
  50. S:=Socket(AF_INET,SOCK_STREAM,0);
  51. if SocketError<>0 then Perror('Client : Socket : ');
  52. WriteLn('*1');
  53. if not Connect(s,isocket,sin,sout)then Perror('Client : Socket : ');
  54. WriteLn('*2');
  55. ReWrite(Sout); Reset(Sin);
  56. WriteLn('*3');
  57. read_to_eof;
  58. Writeln('Sending "USER anonymous#10"');
  59. Write(Sout,'USER anonymous'#10);
  60. read_to_eof;
  61. Writeln('Sending "PASS [email protected]#10"');
  62. Write(Sout,'PASS [email protected]'#10);
  63. read_to_eof;
  64. Writeln('Sending "QUIT#10"');
  65. Write(Sout,'QUIT'#10);
  66. read_to_eof;
  67. shutdown(s,2); close(sin); close(sout);
  68. end.