Hello. I have a client/server application that uses sockets. I've
run into a problem of the server read()'ing a socket and*.
After toying with the code a bit, I think I found out what's wrong:
Here's the problematic server code, in much shorter form:
for( i = 0; i < 3; i++)
{
read(...);
do_Something();
}
Here's the client code:
write(...);
write(...);
write(...);
The above code freezes the client and server, with the server*
on the second read.
Now if I change the client code to:
write(...);
sleep(2);
write(...);
sleep(2);
write(...);
sleep(2);
Everything is fine! Why is that? I'm just writing short strings
(less than 30-50 chars) with each write. My understanding (perhaps
faulty) is that a write() by a client before the server is ready to
read() results in the information being held in a buffer?
If you can help me figure out what's going on, I'd greatly appreciate
it. Thanks!
-Godfrey Degamo,