Class TCPServer[in Socket]

Encapsulates a TCP network service provider.

class TCPServer

more...

Summary

lastErrorNumeric value of system level error that has occoured on the socket.
accept()Waits for incoming connections.
bind()Specify the address and port at which this server will be listening.
dispose()Closes the service and disposes the resources,

Detailed description

class TCPServer


Encapsulates a TCP network service provider.

This class is actually a factory of TCPSockets, that are created as incoming connections are received. As such, it is not derived from the Socket class.

The constructor reserves system resources needed to create sockets and return a TPCServer object that can be used to accept incoming TCP connections.

If the needed system resources are not available, a NetError is raised.

Properties

lastError

Numeric value of system level error that has occoured on the socket.

Methods

accept()

Waits for incoming connections.

TCPServer.accept( [timeout] )

timeoutOptional wait time.
Returns:A new TCPSocket after a successful connection.
Raises:
NetErroron system error.

This method accepts incoming connection and creates a TCPSocket object that can be used to communicate with the remote host. Before calling accept(), it is necessary to have successfully called bind() to bind the listening application to a certain local address.

If a timeout is not specified, the function will block until a TCP connection is received. If it is specified, is a number of millisecond that will be waited before returning a nil. Setting the timeout to zero will cause accept to return immediately, providing a valid TCPSocket as return value only if an incoming connection was already pending.

The wait blocks the VM, and thus, also the other coroutines. If a system error occurs during the wait, a NetError is raised.

bind()

Specify the address and port at which this server will be listening.

TCPServer.bind( addrOrService, [service] )

addrOrServiceAddress at which this server will be listening.
serviceIf an address is given, service or port number (as a string) where to listen.
Raises:
NetErroron system error.

This method binds the server port and start listening for incoming connections. If passing two parameters, the first one is considered to be one of the address that are available on local interfaces; the second one is the port or service name where the server will open a listening port.

If an address is not provided, that is, if only one parameter is passed, the server will listen on all the local interfaces. It is possible to specify jolly IPv4 or IPv6 addresses (i.e. "0.0.0.0") to listen on all the interfaces.

In case the system cannot bind the required address, a NetError is raised. After a successful bind call, TCPServer.accept may be called to create TCPSocket that can serve incoming connections.

dispose()

Closes the service and disposes the resources,

TCPServer.dispose( )

Collects immediately this object and frees the related system resources. Using this object after this call causes undefined results.


Made with faldoc 2.2.1