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

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.