in reply to Problem handling 2 simultaneous socket streams

# NEXT LINE IS BLOCKING --------------------------- if(defined($buf1=<$socket>)) { #put stream2 into buf1

Using buffered IO with non-blocking sockets is a no-no. readline() (<>) won't return until it sees the current delimiter (typically "\n"); if the other end sends data without a delimiter, it will block; if the other end never gets around to sending a delimiter, then it will block forever.

The solution is to use read, sysread or recv, but then you'll need to buffer and track the delimiters yourself, which gets awfully messy.

The whole thing would be far simpler using threads.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.