When will I normally need different ports for client-server communication? (This question is for C# and general socket programming).
I have implemented and been using a simple C# client-server application. Basically:
- server listens for client
- on accepted/connected
- server spawn client thread -
- server waits for client to talk
- client talk
- server respond
- client talk
- server respond etc.
if client stops talking, then server blocks in NetworkStream.Read()
mode forever in that spawned thread unless client-side disconnects.
I am now thinking of the situation where both sides keeps quiet until some event happen on either side then only will the client or server sends data across. As such both needs to be in NetworkStream.Read mode concurrently somehow and also be able to send to each other at the same time (if the event happens on both sides simultaneously).
Do we need different ports in this case or can both client and server be in NetworkStream.BeginRead mode without risking a problem with NetworkStream being in both writing and sending mode at the same time?
Thanks.