I have been breaking my head over a problem with my program. I am
using stream socket programming on UNIX Sun solaris. I have a server
that let multiple client connections using multi-threading. There are
separate threads for each client. I ran into the following problem.
When two (or more clients) connect to the server, I am using the send
function to transfer message to the server. When the first client is
connected, the send/recv function from the client to server works just
fine. Likewise, the send/recv function from the server to the client
works fine. For example, the first client "logs in with username &
password" which is sent to the server for verification. The server
verifies it and sends an "OK" back to the client. In my program, I
send a character "1" indicating the username and password mathces. At
this point in time, the value in the "buf" received by the recv
function in the client is correct.
However, when the second client connects, a second thread is started.
When the second client tries to log in the same way the first client
did, the client side correctly sends the username/password information
to the server (just like the it happened in the first client). After
the server verifies it, the server uses "send" to send the buffer back
to the client. On the client side, the "recv" function which should
have worked the same way as in the first client, does not receive the
character sent from the server. The recv function is empty instead.
I am not sure what is going on. Can someone please send me
suggestions as to how to overcome this problem.