Hi there, Here is my code - use strict; use warnings; use Foo; my $object = new Foo; package Foo; use Bar; sub new { my $class = shift; my $self : shared; $self = &share({}); my $socket = new IO::Socket::INET ( PeerAddr => "localhost", PeerPort => 5250, Proto => 'tcp' ); if(defined $socket) { $self->{socketFileNo} = $socket->fileno; my $response; # eat up the welcome messages from the server my $response = <$socket>; print "Echo:",$response; $response = <$socket>; print "Echo:",$response; my $job = new Bar($self->{socketFileNo}); $job->start; #print "UADD 10101\n"; #print $socket "UADD 10101\n"; #$response = <$socket>; #print $response; #$response = <$socket>; #print $response; #print "LOAD U8 filename\n"; #print $socket "LOAD U8 filename\n"; #$response = <$socket>; #print "\tEcho: $response\n"; } else { $self->{socketFileNo} = undef; } bless $self, $class; return $self } 1; package Bar; use strict; use warnings; use threads; use threads::shared; use IO::Socket; sub new { my $class = shift; my $self : shared; $self = &share({}); $self->{socketFileNo} = shift; bless $self, $class; return $self; } # start the job sub start { my $self = shift; my $socket = undef; if(defined $self->{socketFileNo}) { open $socket, '+<&=' . $self->{socketFileNo}; } if(defined $socket) { my $response; print "UADD 10101\n"; print $socket "UADD 10101\n"; $response = <$socket>; print $response; $response = <$socket>; print $response; print "LOAD U8 filename\n"; print $socket "LOAD U8 filename\n"; $response = <$socket>; print "\tEcho: $response\n"; } } 1; This code produces the following output - Echo: Welcome Echo: Use 'HELP' for help. UADD 10101 202 OK U19 LOAD U8 filename Echo: 406 Command not supported I do not expect the server to reply with - "Echo: 406 Command not supported". However, if I comment out the two lines above concerned with the crea +tion of the Bar object and uncomment the lines which follow, I get - Echo: Welcome Echo: Use 'HELP' for help. UADD 10101 202 OK U19 LOAD U8 filename Echo: 406 Sucessful This is despite the fact that $job->start; should be doing the same th +ings as these uncommented lines. I'm guessing the problem is this line - "open $socket, '+<&=' . $self- +>{socketFileNo};" This is a very cut down version of my code so that I could isolate the + problems. I'm using threads normally, however as you can see I get t +he problem regardless. What might the problem be? It seems I can communicate to and from the +server via $job->start but that things are getting corrupted. Please help, Thanks in advance.
In reply to Problem extracting socket from fileno by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |