I’ve created a TCP Server class that implements the InterprocessConnectionServer, creating InterprocessConnection instances for each client that connects. Everything works great, except for one thing: I would like to be able to get the the actual port and address that the InterprocessConnectionServer is bound to, and on which it is listening. I’m creating the server with a port of 0, so there’s no way of knowing (easily) which port was provided by the OS.
It would be great if serverAddress() and serverPort() functions were provided, or alternately, if the InterprocessConnectionServer’s socket member was made protected so I could add those functions to my own TCP Server class.
I would be using it to display the listen address and port on the UI, so I know which endpoint the client should connect to. The address isn’t so much of a problem since I can store the address that gets passed to beginWaitingForSocket(), but the port is crucial.
Normally when you put up a server you’d provide a known port number, and ask the server to listen on all interfaces unless there’s some specific (Security probably) reason to have it listen on a specific interface.
I didn’T know it was possible to get bind to listen on a random address… does it work providing 0 as a port number for the server?