Difference between revisions of "TWSocket.Accept"
Markus.humm (talk | contribs) (first entry) |
Markus.humm (talk | contribs) (Dup-link fixed) |
||
(One intermediate revision by the same user not shown) | |||
Line 7: | Line 7: | ||
== Description == | == Description == | ||
− | '''Accept''' is used in TCP-Server sockets, mainly the [[RWSocket.OnSessionAvailable|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 [[TWSocket. | + | '''Accept''' is used in TCP-Server sockets, mainly the [[RWSocket.OnSessionAvailable|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 [[TWSocket.Dup|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. | For UDP-connections this is not needed and should not be used. | ||
Line 15: | Line 15: | ||
var socket:TMySocket; // a descendant of TWSocket with overwritten OnDataAvailable | var socket:TMySocket; // a descendant of TWSocket with overwritten OnDataAvailable | ||
− | + | ||
procedure TMyServer.MyOnSessionAvailable(Sender: TObject; ErrCode: Word); | procedure TMyServer.MyOnSessionAvailable(Sender: TObject; ErrCode: Word); | ||
var NewS:TSocket; | var NewS:TSocket; | ||
begin | begin | ||
if ErrCode <> 0 then exit; | if ErrCode <> 0 then exit; | ||
− | + | ||
NewS:=Accept; | NewS:=Accept; | ||
socket:=TMySocket.create(nil); | socket:=TMySocket.create(nil); |
Latest revision as of 10:59, 18 September 2006
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;