2.12.3Class TCPServer

Encapsulates a TCP network service provider.

Class TCPServer
Raise
NetError on system error.

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
acceptWaits for incoming connections.
bindSpecify the address and port at which this server will be listening.
disposeCloses the service and disposes the resources,

Properties

lastError

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

Numeric value of system level error that has occoured on the socket. socketErrorDesc may be used to get a human-readable description of the error. The error is usually also written in the fsError field of the exceptions, if case they are caught.

Methods

accept

Waits for incoming connections.

TCPServer.accept( [timeout] )
timeout Optional wait time.
ReturnA new TCPSocket after a successful connection.
Raise
NetError on 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] )
addrOrService Address at which this server will be listening.
service If an address is given, service or port number (as a string) where to listen.
Raise
NetError on 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 http://www.falconpl.org