uses sockets var sockfd longint saddr TinetSockAddr buf string sin sou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
uses sockets;
var
sockfd:longint;
saddr:TinetSockAddr;
buf:string;
sin,sout:text;
f:textfile;
begin
//creating socket
sockfd:=socket(AF_INET, SOCK_STREAM, 0);
if sockfd = -1
then perror ('error of start socket',1);
saddr.family:=AF_INET;
saddr.port:=htons(80);
saddr.addr:=Longword(StrToNetAddr('193.178.228.214'));;
//connect to server
if not connect (sockfd, saddr, sin, sout)
then perror ('error connect',4);
reset(sin);
rewrite(sout);
flush(sout);
//send query to webserver
writeln(sout,'GET /nod3/em002_32_l2.nup HTTP/1.0');
writeln(sout,'Host: freedom.net.sumy.ua');
writeln(sout,#13);
assignfile(f,'/var/tmp/1');
rewrite(f);
//recive answer.. onlines
while not eof(sin) do
begin
readln(sin,buf);
writeln(f,buf);
end;
close (sout);
close (sin);
close (f);
end.
How get binary file?