listenany

listenany(port_hint) -> (UInt16,TCPServer)

Create a TCPServer on any port, using hint as a starting point. Returns a tuple of the actual port that the server was created on and the server itself.

Examples

julia> listenany(8000)
(8000, TCPServer(TCPSocket(RawFD(50) open, 0 bytes waiting), true, false, false, false, false, false, false, false, 0 bytes waiting)))

This example creates a TCPServer on any available port starting from port 8000. It returns a tuple containing the actual port that the server was created on (in this case, 8000) and the TCPServer object itself.

Common usage example:

julia> port, server = listenany(9000)
(9000, TCPServer(TCPSocket(RawFD(55) open, 0 bytes waiting), true, false, false, false, false, false, false, false, 0 bytes waiting)))

julia> port
9000

julia> server
TCPServer(TCPSocket(RawFD(55) open, 0 bytes waiting), true, false, false, false, false, false, false, false, 0 bytes waiting)

In this example, the listenany function is used to create a TCPServer on any available port starting from 9000. The returned tuple is assigned to port and server variables for further use.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: