A silly socket question
-
Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.
-
Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.
Only one socket can listen on a particular port. But more than one socket can connect to a single port. From your question, it is not clear whether you meant the first or the second. In the first case, the call to Listen() will fail with an exception. Regards Senthil My Blog
-
Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.
Try reading on "non-blocking server socket" in the MSDN. The thing is: if you have a "server loop" which waits on data to arrive on any of these ports, then does some manipulation and loops, you will always have poor performance, as your application will block until you are done with one of the requests. If you decided to use 10 ports in order to offer "10 parallel connections", you totally misunderstood the concept (sorry :)). You should only use different ports for different services (e.g. FTP Control connection on Port 21, HTTP on Port 80, ...) or to seperate user-groups (e.g. Customer1 connects to FTP on port 21, Customer2 uses Port 23, ...). Specifically, you might want to read into Delegates, Callbacks, etc. These are, IMHO, the easiest way to create socket-using apps without doing manual multithreading. Cheers Sid