Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Sockets/Pascal/sockets-1.pas
Normal file
55
Task/Sockets/Pascal/sockets-1.pas
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
Program Sockets_ExampleA;
|
||||
|
||||
Uses
|
||||
{ Free Pascal RTL sockets unit }
|
||||
sockets;
|
||||
|
||||
Var
|
||||
TCP_Sock: integer;
|
||||
Remote_Addr: TSockAddr;
|
||||
|
||||
Message: string;
|
||||
PMessage: Pchar;
|
||||
Message_Len: integer;
|
||||
|
||||
|
||||
Begin
|
||||
{ Fill the record (struct) with the server's address information }
|
||||
With Remote_Addr do
|
||||
begin
|
||||
Sin_family := AF_INET;
|
||||
Sin_addr := StrToNetAddr('127.0.0.1');
|
||||
Sin_port := HtoNs(256);
|
||||
end;
|
||||
|
||||
{ Returns an IPv4 TCP socket descriptor }
|
||||
TCP_Sock := fpSocket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
|
||||
{ Most routines in this unit return -1 on failure }
|
||||
If TCP_Sock = -1 then
|
||||
begin
|
||||
WriteLn('Failed to create new socket descriptor');
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
{ Attempt to connect to the address supplied above }
|
||||
If fpConnect(TCP_Sock, @Remote_Addr, SizeOf(Remote_Addr)) = -1 then
|
||||
begin
|
||||
{ Specifc error codes can be retrieved by calling the SocketError function }
|
||||
WriteLn('Failed to contact server');
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
{ Finally, send the message to the server and disconnect }
|
||||
Message := 'Hello socket world';
|
||||
PMessage := @Message;
|
||||
Message_Len := StrLen(PMessage);
|
||||
|
||||
If fpSend(TCP_Sock, PMessage, Message_Len, 0) <> Message_Len then
|
||||
begin
|
||||
WriteLn('An error occurred while sending data to the server');
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
CloseSocket(TCP_Sock);
|
||||
End.
|
||||
28
Task/Sockets/Pascal/sockets-2.pas
Normal file
28
Task/Sockets/Pascal/sockets-2.pas
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Program Sockets_ExampleB;
|
||||
|
||||
Uses
|
||||
sockets;
|
||||
|
||||
Var
|
||||
TCP_Sock: integer;
|
||||
Remote_Addr: TSockAddr;
|
||||
|
||||
Message: string;
|
||||
PMessage: Pchar;
|
||||
Message_Len: integer;
|
||||
|
||||
Begin
|
||||
Remote_Addr.Sin_family := AF_INET;
|
||||
Remote_Addr.Sin_addr := StrToNetAddr('127.0.0.1');
|
||||
Remote_Addr.Sin_port := HtoNs(256);
|
||||
|
||||
TCP_Sock := fpSocket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
|
||||
fpConnect(TCP_Sock, @Remote_Addr, SizeOf(Remote_Addr));
|
||||
|
||||
Message := 'Hello socket world';
|
||||
PMessage := @Message;
|
||||
Message_Len := StrLen(PMessage);
|
||||
|
||||
fpSend(TCP_Sock, PMessage, Message_Len, 0);
|
||||
End.
|
||||
Loading…
Add table
Add a link
Reference in a new issue