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,&nbsp; 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


In reply to how send message without new-line terminator on IO::Socket by earlati2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.