AsyncServerSocket represents an asynchronous server socket (listening TCP socket). An application creates an instance of an AsyncServerSocket to listen for incoming TCP connections on a given port. When a connection is received either, depending on the
configuration, an event is pushed onto the sink associated with the server socket or a callback is invoked with the accepted connection
as a parameter.
Opening an AsyncServerSocket
There are four standard ways to open an AsyncServerSocket each explained in the 5 minute introduction
Standard mode
Offerable mode
Queue mode
Callback mode
Accepting a new Socket
The main purpose of the accept() method of a server-socket is to accept new sockets. However, when the service is suffering from overload the client might decline to accept new sockets. This can be done by simply not calling the accept() method until the system is ready to process new connections. An AsyncServerSocket automatically accept all new sockets. These sockets are then placed onto a completion-queue ready to be processed by the user. To control the acceptance of new socket the client might instead insert a guard. This guard must then be called by the AsyncServerSocket before it accepts a new connection. For example, the following policy dictates that only if there is more then 100000 bytes of available memory the AsyncServerSocket must accept 5 new sockets (before calling acceptNext again):
The following example opens an AsyncServerSocket, binds it and
starts accepting new sockets using the LowMemoryPolicy.
Whenever a new socket is accepted the AsyncServerSocket automatically posts an instance of an AsyncServerSocket.SocketAccepted event to mySink. If no policy is specified when calling startAccepting the server-socket just uses the default policy which accepts all new sockets.
