TWSocket.Accept
Main page -> ICS component reference -> TWSocket -> Accept
Definition
method Accept: integer;
Description
Accept is used in TCP-Server sockets, mainly the OnSessionAvailable eventhandler, to establish a incommind connection. Accept returns the necessary informations about the connection in a TSocket (don't confuse it with a TWSocket) which can be used to initialize the socket the connection will be transfered to via dup. The connection should be transfered to another socket, otherwise the server can't accept new connections on the port he listens on.
For UDP-connections this is not needed and should not be used.
Example
The following example implements the OnSessionAvailable of a simple TCP-Server which transfers the accepted connection to another socket so that other incomming connections can be accepted as well. Since the socket the connection is transfered to is a global variable here only one connection can be accepted, but this example is simply for showing the basics.
var socket:TMySocket; // a descendant of TWSocket with overwritten OnDataAvailable procedure TMyServer.MyOnSessionAvailable(Sender: TObject; ErrCode: Word); var NewS:TSocket; begin if ErrCode <> 0 then exit; NewS:=Accept; socket:=TMySocket.create(nil); socket.dup(NewS); end;