3

你如何在 Pascal 中使用网络套接字?

4

4 回答 4

5

这是取自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.
于 2008-08-19T22:09:15.207 回答
1

If you're using FPC or Lazarus(which is basically a rad IDE for FPC and a clone of delphi) you could use the Synapse socket library. It's amazing.

于 2012-05-05T07:01:36.253 回答
0

如果您使用 Delphi,我强烈推荐Indy套接字,一组用于轻松操作套接字和许多其他 Internet 协议(HTTP、FTP、NTP、POP3 等)的类

于 2008-08-22T16:06:05.430 回答
0

您不能将 OpenSSL 与 Delphi 2007 附带的 Indy 版本 10.5 一起使用。您必须从http://www.indyproject.org/下载版本 10.6并将其安装到 IDE 中。

请注意,其他包可能使用 Indy,例如 RemObjects,因此它们也必须重新编译,并且由于交叉引用,这可能会很棘手。

于 2008-09-01T19:26:40.047 回答