Hi all.
I'm building kind of a hub-and-spokes type application with a central server and several remote clients that speak only to the server.
On a client, there are several (5-6) threads that all need to talk to the server at varying times. To make life easier, I made a SocketHandle class to wrap the socket operations, and each thread has a reference to the SocketHandle. The server only listens on one port, say 1234, and the threads can call the SendData method of the SocketHandle to send data to the server. Any thread that sends data also expects an acknowledgement from the server, and will listen on the open socket for a response for a certain time before it gives up and closes the socket.
Question 1: I built the SendData method as synchronized, so that only one socket would be open at a time. But, I assume (from my limited networking knowledge - hehe) that opening a socket would choose a different high-level port each time, so could every thread theoretically open a socket at once and the communications not interfere with each other? In other words, wouldn't the TCP sessions naturally make sure that the responses get sorted out to the correct senders? If so, do I need synchronization of the SendData method at all? (the point was to keep signals from getting crossed between threads)
Question 2: The clients will also need a server socket listening on the same port (say 1234) for the server to "push" data down every once in a while. Would that server socket interfere with the communications of the client threads? And can I guarantee that if a client is listening on 1234 that one of the threads won't choose 1234 to send on? Or does that matter?
Sorry so long-winded. Feel free to get me back by being long-winded in response
TIA,
Brad
Brad Gunsalus
bardley90@hotmail.com
I'm building kind of a hub-and-spokes type application with a central server and several remote clients that speak only to the server.
On a client, there are several (5-6) threads that all need to talk to the server at varying times. To make life easier, I made a SocketHandle class to wrap the socket operations, and each thread has a reference to the SocketHandle. The server only listens on one port, say 1234, and the threads can call the SendData method of the SocketHandle to send data to the server. Any thread that sends data also expects an acknowledgement from the server, and will listen on the open socket for a response for a certain time before it gives up and closes the socket.
Question 1: I built the SendData method as synchronized, so that only one socket would be open at a time. But, I assume (from my limited networking knowledge - hehe) that opening a socket would choose a different high-level port each time, so could every thread theoretically open a socket at once and the communications not interfere with each other? In other words, wouldn't the TCP sessions naturally make sure that the responses get sorted out to the correct senders? If so, do I need synchronization of the SendData method at all? (the point was to keep signals from getting crossed between threads)
Question 2: The clients will also need a server socket listening on the same port (say 1234) for the server to "push" data down every once in a while. Would that server socket interfere with the communications of the client threads? And can I guarantee that if a client is listening on 1234 that one of the threads won't choose 1234 to send on? Or does that matter?
Sorry so long-winded. Feel free to get me back by being long-winded in response
TIA,
Brad
Brad Gunsalus
bardley90@hotmail.com