earlati2 has asked for the wisdom of the Perl Monks concerning the following question:
I suppose my question is a very simple one, but I didn't find a real solution so I hope someone ca help.
I have 2 programma which send each other data using the socket via module Io::Socket
the server is somethink like this:
use IO::Socket; my ( $stmp, $nchar ); $| = 1; my $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '2040', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; $sock->autoflush(); while( 1 ) { my $new_sock = $sock->accept(); $| = 1; $new_sock->autoflush(); while(1) { $nchar = read( $new_sock, $stmp, 1 ); print "$stmp"; print $new_sock "$stmp"; } } close($sock);
------- while the cliente is as follow
my $sock = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => $remote_port, Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; $sock->autoflush(); ae_util::mylog( "SendSOCKT: $msg " ); print $sock "$msg\n"; $stmp = <$sock>; chomp $stmp; ae_util::mylog( "AnswSOCKT: $stmp " ); close( $sock );
The problem is that if I send a message terminated with new-line ( as print $sock "$msg\n"; ) is all ok
If I send the message without the newline at the end the program hangs, the server receive the data , and mybe send the answer , but the cliente didn't receive the answer.
Where I' m wrong in this and how can send message without end-line terninator on the socket ?
thank for the help, Enzo
Formatting cleansed by holli as per consideration
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how send message without new-line terminator on IO::Socket
by Corion (Patriarch) on Jul 26, 2006 at 08:32 UTC | |
by earlati2 (Beadle) on Jul 26, 2006 at 09:03 UTC | |
by Corion (Patriarch) on Jul 26, 2006 at 09:26 UTC | |
by earlati2 (Beadle) on Jul 26, 2006 at 14:58 UTC | |
by tye (Sage) on Jul 26, 2006 at 15:12 UTC | |
|