I’ve got a client app which has to connect to a server and register for waiting, that is, it wants to be notified when the server is done with some processing. Ideally, I want to keep this client as simple as possible, but the question is, how to “register for waiting”. I could keep the socket open and do a blocking read, and as soon as the server is done, it’ll send some data to the client and I’m done; unfortunately this blocks one port on the server for quite some time.
What alternatives are there? I could pick a random port on the client side, and listen for a connection there, but this requires me to pick a free random port — and I’m not sure how to do this best in C#? I thought about checking the local port used while sending to the server, and re-using this; I wonder if there is some recommended way to solve this. Polling from the client is out of question, as the time between finish and notification shouldn’t be too long.
Pass
0as the port number to theIPEndPointconstructor: