Listen for an incoming TCP connection on the specified port.
First available in version 3.0 build 2039.
port - Port to listen on.
localAddress - [Optional] - Local address on which the socket will be created. Default value is 0.0.0.0.
No output parameters.
This method can only be called asynchronously.
TCP.listen creates a server socket on the specified port.
It is possible to create a server socket on a specific network interface by specifying the localAddress of the interface in question. This is useful, for example, for creating bridging software between two subnets, where one socket is used to receive messages from one subnet and relays them to the other subnet.
When a client connects to the socket, an onConnect notification is sent, passing the address of the client to the event handler.
When the client disconnects, an onDisconnect event notification is sent to the event handler, and the socket is automatically put back in the listening mode, waiting for the next connection.
Though a socket can only connect to one client at a time, it is possible to set up multiple server sockets all listening on the same port. Clients will connect to the listening sockets in a random fashion; no assumptions can be made as to the sequence in which sockets will be connected.