You have to use the same socket for both send and receive. I suspect you're not issuing use strict and use warnings here. Why should a variable named $s_receive turn into $s_send?!? Moreover, the print scalar <$s_send> is really obscure - what do you want to obtain?

Here's a skeleton for your application, but again you have to fill in the actual implementation of the algorithm. You can also find some example of bidirectional communication.

#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; + # Main socket, it's only for accepting connections my $sock = IO::Socket::INET->new(LocalPort => 10000, Proto => 'tcp', List +en => 2) or die "unable to initiate socket: $!"; print STDERR "ready to accept connections\n"; + # Working sockets, they're bidirectional connections towards each # single client, so they're to be used for actual communications my $conn1 = $sock->accept() or die "accept(): $!"; print STDERR "client 1 connected\n"; + my $conn3 = $sock->accept() or die "accept(): $!"; print STDERR "other client connected\n"; + # Core of algorithm should go here, just some examples of IO given # Read from client #1 my $rec1 = <$conn1>; # Send something to client #1 print $conn1 "Hey #1, I heard you saying [$rec1]\n"; # Read from the other client my $rec3 = <$conn3>; # Send something to it as well print $conn3 "You're there, #3... did you say [$rec3]?\n"; $_->close foreach ($conn3, $conn1, $sock);

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re^3: sockets and such in Perl by polettix
in thread sockets and such in Perl by scotchfx

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.