Ok so I've been trying to teach myself some socket programming. I wrote myself a little C# application with an async server and I understand most of it, except for the following:
So the server has a port it listens on for connections then when it receives a connection it creates a different socket to do the communication on. This it what I dont understand... How does the communication happen between the client and the server when in theory the client has no idea what port has been elected for this new connection?
Thanks for all your answers
Edit: As far as I understand the listening thread listens on the default port, but all messages are then handled on a different socket for each client?
Edit Again: Some how you guys are misunderstanding my question. I understand normal socket communication. My problem is with an async server where the listening socket is different from the connecting socket. Ie.
- Server listens on default port
- Client attrmpts to connect.
- Server receiver request.
- Server then creates a communication socket between client and server and continues listening on the default port.
My problem is at the last step. How does the client now know how to communicate on the new socket? Here is some sample code http://msdn.microsoft.com/en-us/library/5w7b7x5f.aspx