Socket error lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- xmldom · 2012-01-21 13:54 Hello. I need to use socket in my application. I found this code on http://www.linuxsoft.cz/article.php?id_article=125 : Code: [Select]program IP_server; { -*- mode:delphi; -*- } uses sockets,inet,linux; const    port = 4456;      { Cislo portu na kterem budeme naslouchat } var    s     : longint;       { socket }    sin,sout : text;          { pascalske proudy }    i     : integer;    c     : char;    pid     : longint;    line     : string;    addr     : TInetSockAddr; function getName(addr :longint ):string; var    h  : THost;    a  : longint; begin    a:=NetToHost(addr);    h.AddressLookup(THostAddr(a));    getName:=h.Name;    h.done; end; begin    s:=socket(AF_INET,SOCK_STREAM,0);    if s=-1 then begin       halt(1);    end;    addr.family:=AF_INET;  { Jedna se o adresu domeny INET, tj. IPv4 }    addr.port:=ShortHostToNet(port);    addr.addr:=0;          { Naslouchame na 0.0.0.0 tj. na vsech rozhranich }    if not bind(s,addr,sizeof(addr)) then halt(1);    if not listen(s,5) then halt(1);    while accept(s,addr,sin,sout) do begin       pid:=fork;       if pid=-1 then halt(2);       if pid=0 then begin reset(sin); rewrite(sout); writeln('Server: prichozi spojeni od:',getName(addr.addr)); writeln(sout,'Mnauu'); repeat     readln(sin,line);     for i:=0 to length(line) div 2-1 do begin        c:=line[i+1];        line[i+1]:=line[length(line)-i];        line[length(line)-i]:=c;     end;     writeln(sout,line); until eof(sin); close(sin); close(sout); halt(0);       end;    end; end.Code: [Select]program Unix_Client; uses sockets,inet; const    port = 4456;               { port serveru } var    s     : longint;        { socket }    sin,sout : text;           { pascalske proudy }    line     : string;    addr     : TInetSockAddr;      { struktura pro connect }    host     : THost;          { objekt hostitele (coz zni hrozne ucene ^_~) } begin    if paramcount<>1 then begin       writeln('Usage: ',paramstr(0),'
');       halt(4)    end;    s:=socket(AF_INET,SOCK_STREAM,0);    if s=-1 then begin       halt(1);    end;    host.NameLookup(paramstr(1));    addr.family:=AF_INET;               { Rodina adres, tj AF_INET }    addr.port:=ShortHostToNet(port);     addr.addr:=HostToNet(LongInt(host.IPAddress)); { IP adresa serveru }    host.done;    if not connect(s,addr,sin,sout) then halt(2);    reset(sin);    rewrite(sout);    repeat       readln(sin,line);       writeln(line);       readln(line);       if (line='') then break;       writeln(sout,line)    until false;    close(sin);    close(sout); end.   But I can't compile it: Code: [Select]f:\pascal>fpc ip-client.pas Free Pascal Compiler version 2.4.2 [2011/03/08] for i386 Copyright (c) 1993-2010 by Florian Klaempfl Target OS: Win32 for i386 Compiling ip-client.pas Fatal: Can't find unit inet used by Unix_Client Fatal: Compilation aborted Error: c:\lazarus\fpc\2.4.2\bin\i386-win32\ppc386.exe returned an error exitcode  (normal if you did not specify a source file to be compiled) f:\pascal> f:\pascal>fpc ip-server.pas Free Pascal Compiler version 2.4.2 [2011/03/08] for i386 Copyright (c) 1993-2010 by Florian Klaempfl Target OS: Win32 for i386 Compiling ip-server.pas Fatal: Can't find unit inet used by IP_server Fatal: Compilation aborted Error: c:\lazarus\fpc\2.4.2\bin\i386-win32\ppc386.exe returned an error exitcode  (normal if you did not specify a source file to be compiled) f:\pascal> Where I do an error? Unit "inet" is not build in fpc? ---------------------------------------------------------------------- marcov · 2012-01-21 14:16 That's a very old example for FPC 1.0. Better - try one of the socketsuites (Synapse, Indy) - or search for a newer (post 2005) example. ---------------------------------------------------------------------- Shebuka · 2012-01-23 11:00 I'v done recently a test project for a bug that is essentially what you need to take inspiration from: http://bugs.freepascal.org/view.php?id=20484 (attached file)