in reply to Socket deadlock doubt in code

server.pl

while ( defined ($response = <CLIENT>)){ ...

client.pl

while ($line = <SOCKET>) { print SOCKET "Client says hellooooo toooo !!!"; SOCKET->autoflush(); ...

One problem is that you're trying to read lines on the server side with <...> (aka readline), but on the client side you're not writing any newlines...  The effect of this is that the server hangs in $response = <CLIENT> waiting for a newline.

Note that flushing and a communication protocol involving newlines are two different things. In other words, flushing some output does not add a newline.

P.S.: SOCKET->autoflush sets an operation mode of the handle - as opposed to SOCKET->flush - so the former needs to be called only once.

Replies are listed 'Best First'.
Re^2: Socket deadlock doubt in code
by sajanagr (Acolyte) on Jun 23, 2010 at 05:18 UTC
    Hi

    Thanks for the reply. I have done the required changes. Now, the new code is working fine. But couple of issues are there.

    This is how it is, I have taken some information from client side and now I am doing some manipulations and have a IF condition.

    In this IF condition I have sent some information to client back, it works perfectly fine. But, when i tried to print something in this IF condition, it doesn't print anything, but the information in IF condition is sent successfully to the client.

    I am not able to understand this issue ?

      Also, my gethostbyaddr function is not working here. It is failing to give me client's hostname. Works fine with same machine as server-client.

      The entries in /etc/hosts and /etc/resolv.conf are perfectly fine connected to the same domain.

        gethostbyname relies on a functioning DNS system. Make sure things like nslookup and traceroute work properly. The other place you might be going wrong is that in a scalar context, gethostbyname returns the packed ip address, though I'm not sure why you're looking up the hostname from a hostname to begin with.

        As for the printing issue, I suspect that you are Suffering from Buffering.

        Update: oops, gethostbyname is irrelevant here but the DNS still needs to work.