- Norah Jones
ServerSocket
IServerSocket
ServerSocket Methods
ServerSocket() | Constructor for the ServerSocket class |
Accept() | Accepts the connection request and ties it to a ClientSocket object |
Close() | Closes the server socket and shuts down the listener |
AddSocketConnectHandler() | Registers an event handler for processing a connection request using a method reference |
AddSocketConnectHandler() | Registers an event handler for processing a connection request using an IClientSocket reference |
OnSocketConnect() | Virtual method to handle SocketConnectEvent - can be overridden |
IServerSocket Methods
OnSocketConnect() | Virtual method to handle SocketConnectEvent |
Derived Classes
None
See Also
Class Hierarchy, ClientSocket, SocketConnectEvent
public method ServerSocket(int PortNumber)
Parameters
None
Return Value
None
Description
Constructor for the ServerSocket class. For each ServerSocket object which is created, a new internal OS thread is created to listen for incoming connections on the specified socket port. This happens automatically. The main responsibility of the user of this class is to create a SocketConnectEvent handler and perform the 'Accept()' using a new ClientSocket object.
ServerSocket Class
public method Accept(ClientSocket Socket)
Parameters
Socket
Client socket object to be tied to the remote socket
Return Value
None
Description
This method accepts the incoming socket connection. It should be called from within a SocketConnectEvent handler. A new ClientSocket object needs to be created and is then passed into the 'Accept()' call. This sets up a two way connection with the remote socket which made the connection request. The ClientSocket object autimatically creates a SocketStream object to perform this communication. A 'ClientSocket.Write()' call to the socket stream object sends a message to the remote socket and a 'ClientSocket.Read()' call reads all or part of a message sent from the remote socket. The 'Read()' should only be called from within a SocketReceiveEvent handler.
ServerSocket Class
public virtual method Close()
Parameters
None
Return Value
None
Description
This virtual method closes the socket for the server. The internal OS thread associated with this server socket, which listened on the specified port, is also shut down as a result of closing the server.
ServerSocket Class
public method AddSocketConnectHandler(SocketConnectHandler Handler, Base ExtraObject = null)
Parameters
Handler
Method reference to be executed when the event occurs
ExtraObject
Optional object which will be sent along to each event handler when it is executed
Return Value
NONE
Description
This method registers a method reference to be executed when a connection request comes in on the associated port. An optional object can also be registered which will be sent to each event handler as it is executed.
The event handler should then accept the connection using 'Accept()' and a new 'ClientSocket' object.
As is true with all Aztec event handling, this method can be called by any thread. When the event occurs, each registered event handler is scheduled to execute within the thread that registered it. So an event sent to one thread can be handled by event handlers executing in one or more other threads.
The SocketConnectHandler data type represents a method reference specific to a handler for SocketConnectEvent. SocketConnectHandler is defined as follows:
public type<method<SocketConnectEvent,Base>> SocketConnectHandler
Given this definition, the method handler must be defined with the following signature (name can be anything):
public method SocketConnectMethod(SocketConnectEvent event, Base Extra) { }.
ServerSocket Class
public method AddSocketConnectHandler(IServerSocket Interface, Base ExtraObject = null)
Parameters
Interface
Reference to an IServerSocket object
ExtraObject
Optional object which will be sent along to each event handler when it is executed
Return Value
NONE
Description
This method registers an IServerSocket interface object to be executed when a socket connection request comes in on the associated port. An optional object can also be registered which will be sent to each event handler as it is executed.
As is true with all Aztec event handling, this method can be called by any thread. When the event occurs, each registered event handler is scheduled to execute within the thread that registered it. So an event sent to one thread can be handled by event handlers executing in one or more other threads.
When a socket connection request is received, the OnSocketConnect() method within the Interface object will be executed.
ServerSocket Class
public method virtual OnSocketConnect(SocketConnectEvent ConnectEvent, Base ExtraObject)
Parameters
ConnectEvent
SocketConnectEvent object associated with the event
ExtraObject
Optional object sent along from when it was registered
Return Value
NONE
Description
This method is the default event handler for SocketConnectEvent within the server socket. It is invoked internally as a result of receiving a socket connection request on the port associated with this server socket object. This method in turn executes every registered handler with the same argument list which comes in. Both implementations of the ServerSocket.AddSocketConnectHandler() method register the event handlers which get invoked by this method.
If this method is overridden by a class derived from ServerSocket, it must call this implementation of the method if it needs to execute handlers registered with the ServerSocket.AddSocketConnectHandler() methods.
ServerSocketClass
public method virtual OnSocketConnect(SocketConnectEvent ConnectEvent, Base ExtraObject)
Parameters
ConnectEvent
SocketConnectEvent object associated with the event
ExtraObject
Optional object sent along from when it was registered
Return Value
NONE
Description
This virtual method is the event handler for a SocketConnectEvent within the IServerSocket interface class. The method which overrides it is invoked for a SocketConnectEvent within a ServerSocket object when the interface object is registered with the ServerSocket.AddSocketConnectHandler() method.
IServerSocket Class