Sockets in Pascal

How do you use network sockets in Pascal?

+3
source share
4 answers

Here is an example taken from http://www.bastisoft.de/programmierung/pascal/pasinet.html

program daytime;

{ Simple client program }

uses
   sockets, inetaux, myerror;

const
   RemotePort : Word = 13;

var
   Sock : LongInt;
   sAddr : TInetSockAddr;
   sin, sout : Text;
   Line : String;

begin
   if ParamCount = 0 then GenError('Supply IP address as parameter.');

   with sAddr do
   begin
      Family := af_inet;
      Port := htons(RemotePort);
      Addr := StrToAddr(ParamStr(1));
      if Addr = 0 then GenError('Not a valid IP address.');
   end;

   Sock := Socket(af_inet, sock_stream, 0);
   if Sock = -1 then SockError('Socket: ');

   if not Connect(Sock, sAddr, sizeof(sAddr)) then SockError('Connect: ');
   Sock2Text(Sock, sin, sout);
   Reset(sin);
   Rewrite(sout);

   while not eof(sin) do   
   begin
      Readln(sin, Line);
      Writeln(Line);
   end;

   Close(sin);
   Close(sout);
   Shutdown(Sock, 2);
end.
+4
source

If you use FPC or Lazarus (basically it is a rad IDE for FPC and a delphi clone), you can use the Synapse socket. This is amazing.

+1
source

Delphi, Indy , - (HTTP, FTP, NTP, POP3 ..)

0

OpenSSL Indy 10.5, Delphi 2007. 10,6 http://www.indyproject.org/ IDE.

Note that other packages may use Indy, such as RemObjects, and therefore need to be recompiled too, and this can be difficult due to cross-referencing.

0
source

Source: https://habr.com/ru/post/1696456/


All Articles