gpt4 book ai didi

帕斯卡套接字

转载 作者:行者123 更新时间:2023-12-02 00:33:52 26 4
gpt4 key购买 nike

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

最佳答案

以下示例取自 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.

关于帕斯卡套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com