Do I need to setup a UDP connection specifically to use recv? To do this do I only need to specify 'Proto'=>'udp' when opening the socket?

I am attempt to read a string back through the <$t_socket> -it is a name that I need to find a eq match for - the link below has a better description of my project:

http://www.perlmonks.org/?node_id=472004

Essentially I am trying to match input given to me by a First process, if I match this input in the Second process I send it to the Third process to see if I have yet another match. However if the First/Second match is not confirmed by the Third process, then I need to respond to the Second to find another match.

Sending the data from First, to Second, to Third works fine.

My problem comes in being able to establish a connection "downstream" (Third, to Second, to First) using the same set of sockets that I originally used to send data "upstream". In short, I cannot seem to pick up a response from Third to Second, and then from Second to First.

The code for my Third process is appended below - as you can see I am adding a newline at the end of the string before I send it back to the Second process - but for some reason the while(<$t_socket>){...} loop never executes - either it is indefinitely waiting on the <$t_socket> or it is skipping the loop altogether.

use IO::Socket; use strict; use warnings; my $PORT = shift or die "Please specify First port number\n"; #my $file = shift or die "Please specify input file\n"; my $socket = IO::Socket::INET->new('LocalPort' => $PORT, 'Proto' => 'tcp', 'Listen' => 2) or die "Third: Can't create socket to Second($!)\n"; my $match = "brenna"; print "Third listening\n"; while (my $second = $socket->accept) { #setup acknowledgement message to Second my $host = gethostbyaddr($second->peeraddr, AF_INET); my $port = $second->peerport; while (<$second>) { my $name = $_; chomp($name); print "[$host $port] $name\n"; #print $socket "$.: $name\n"; if($name eq $match) { print "Third sending \"$name\" to Second\n"; print $socket "$name\n"; #close $second or die "Can't close ($!)\n"; } } } die "Third: Can't accept receive socket from Second($!)\n";
Any help/advice you can offer to help me figure this out would be much appreciated!

In reply to Re^2: Read/Write Socket question (Bidirectional my ass...) by scotchfx
in thread Read/Write Socket question (Bidirectional my ass...) 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.