You can simply your code greatly by using IO::Socket::INET. For example,
use Socket qw( PF_INET SOCK_STREAM inet_aton ); $proto = getprotobyname("tcp"); $iaddr = inet_aton($host) or die "Invalid host : $!\n"; $paddr = sockaddr_in($port,$iaddr); socket(SOCKET,PF_INET,SOCK_STREAM,$proto) or die "socket: $!\n"; connect(SOCKET,$paddr) or die "connect: $!\n"; my $old_fh = select(SOCKET); $|=1; select($old_fh);

can be written as:

use IO::Socket::INET qw( ); my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port, ) or die("Unable to create client socket: $!\n");

The server would be

use IO::Socket::INET qw( ); use Socket qw( SOMAXCONN ); my $server_sock = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, ReuseAddr => 1, Listen => SOMAXCONN, ) or die("Unable to create server socket: $!\n");

As an additional bonus, IO::Socket::INET turns on autoflush for the socket, so if kyle is correct, it will also fix your problem.


In reply to Re: Client/server issues - Server is not receiving information until client closes the connection by ikegami
in thread Client/server issues - Server is not receiving information until client closes the connection by sergey

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.