in reply to Re: Read/Write Socket question (Bidirectional my ass...)
in thread Read/Write Socket question (Bidirectional my ass...)

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!

Replies are listed 'Best First'.
Re^3: Read/Write Socket question (Bidirectional my ass...)
by castaway (Parson) on Jul 05, 2005 at 21:56 UTC
    No you don't, or I wouldnt have suggested using it. recv works with a socket, no matter how it is connected.

    Does $name in fact equal $match? ie is the third one actually answering at all? Please try testing it using telnet, or give the data that you are using.

    C.