Function Accept (Sock:Longint;Var Addr;Var Addrlen:Longint) : Longint;
Accept accepts a connection from a socket Sock, which was listening for a connection. The accepted socket may NOT be used to accept more connections. The original socket remains open.
The Accept call fills the address of the connecting entity in Addr, and sets its length in Addrlen. Addr should be pointing to enough space, and Addrlen should be set to the amount of space available, prior to the call.
Errors are reported in SocketError, and include the following:
Program server;
{
Program to test Sockets unit by Michael van Canneyt and Peter Vreman
Server Version, First Run sock_svr to let it create a socket and then
sock_cli to connect to that socket
}
uses Linux,Sockets;
const
SPath='ServerSoc';
Var
FromName : string;
Buffer : string[255];
S : Longint;
Sin,Sout : Text;
procedure perror (const S:string);
begin
writeln (S,SocketError);
halt(100);
end;
begin
S:=Socket (AF_UNIX,SOCK_STREAM,0);
if SocketError<>0 then
Perror ('Server : Socket : ');
UnLink(SPath);
if not Bind(S,SPath) then
PError ('Server : Bind : ');
if not Listen (S,1) then
PError ('Server : Listen : ');
Writeln('Waiting for Connect from Client, run now sock_cli in an other tty');
if not Accept (S,FromName,Sin,Sout) then
PError ('Server : Accept : ');
Reset(Sin);
ReWrite(Sout);
Writeln(Sout,'Message From Server');
Flush(SOut);
while not eof(sin) do
begin
Readln(Sin,Buffer);
Writeln('Server : read : ',buffer);
end;
Unlink(SPath);
end.