next up previous contents index
Next: Connect Up: Functions and Procedures Previous: Bind

Connect

   

Declaration:

Function Connect (Sock:Longint;Var Addr;Addrlen:Longint) : Boolean;

Description:

Connect opens a connection to a peer, whose address is described by varAddr. AddrLen contains the length of the address.

The type of Addr depends on the kind of connection you're trying to make, but is generally one of TSockAddr or TUnixSockAddr.

Errors:

Errors are reported in SocketError.

See also:

Listen, Bind,Accept

Example
Program Client;

{
  Program to test Sockets unit by Michael van Canneyt and Peter Vreman
  Client Version, First Run sock_svr to let it create a socket and then
  sock_cli to connect to that socket
} 

uses Sockets,Linux;
        
procedure PError(const S : string);
begin
  writeln(S,SocketError);
  halt(100);
end;   


Var
  Saddr    : String[25];
  Buffer   : string [255];
  S        : Longint;
  Sin,Sout : Text;
  i        : integer;
begin
  S:=Socket (AF_UNIX,SOCK_STREAM,0);
  if SocketError<>0 then 
   Perror('Client : Socket : ');
  Saddr:='ServerSoc';
  if not Connect (S,SAddr,Sin,Sout) then
   PError('Client : Connect : ');
  Reset(Sin);
  ReWrite(Sout);
  Buffer:='This is a textstring sent by the Client.';
  for i:=1 to 10 do
   Writeln(Sout,Buffer);
  Flush(Sout);
  Readln(SIn,Buffer);
  WriteLn(Buffer); 
  Close(sout);
end.



Michael Van Canneyt
Thu Sep 10 13:59:33 CEST 1998