in reply to Re^2: Simple question regarding Bidirectional socket programming
in thread Simple question regarding Bidirectional socket programming
First, you should read from CLIENT, not from $client_addr:
while ( defined ($response = <CLIENT>) ){
Next, you have to flush (or autoflush) when you write something on either side. Otherwise, due to buffering, the messages will not be available on the other side right away, resulting in a deadlock, because both sides will wait for the other side to say something... One way would be to use IO::Handle:
use IO::Handle; ... print CLIENT "Hello from the server \n\n "; CLIENT->flush(); ...
and similarly on the client side.
Also, as both client and server are in a readline while loop, you'll likely want to have some protocol that defines when to stop reading and terminate the connection.
Finally, when you read lines on the server side, you also have to print a line on the client side:
print SOCKET "Client says hellooooo toooo !!! \n"; # ^^ SOCKET->flush();
Otherwise, the server will hang in $response = <CLIENT>, waiting for the newline...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Simple question regarding Bidirectional socket programming
by sajanagr (Acolyte) on Jun 15, 2010 at 10:27 UTC | |
by almut (Canon) on Jun 15, 2010 at 11:26 UTC | |
by ikegami (Patriarch) on Jun 15, 2010 at 18:11 UTC | |
by sajanagr (Acolyte) on Jun 16, 2010 at 06:27 UTC |