views:

300

answers:

1

any ideas why stream.flush(); won't work?

boost::asio::ip::tcp::iostream stream("localhost","5000");
assert(stream.good());  
stream << 1;
stream.flush();
while(true);

it's only flushed if the loop is removed and the line
boost::this_thread::sleep(boost::posix_time::seconds(1));
is executed (much later).

Thanks

Update: I did some more debugging and the problem is in fact not the flush command. If I let my code connect to a netcat server everything works fine. I assume the problem is that both client and server are in the same process (I create two threats one acts as a server one as a client). When I put them in separate processes everything works fine, but when both are in the same process the transfer stalls until sleep is called... (this is only for testing reasons, later both will run on different servers).

Platform is WindowsXP.

Any ideas why this is happening?

A: 

How do you know flush doesn't work? I suspect that your while(true) puts very high load on your system. This can prevent the recipient from running.

Try the same code with recipient on an other host to check.

Update: I think the problem is the empty while(true); I would use something like:

while(true) {
    sleep(1);
}

or nanosleep both defined in header ctime. Finally yes I believe running server and client in the same process will get you in more trouble.

/Tobias

Tobias