Professional Web Applications Themes

Read/Write IO on socket file descriptor - PERL Miscellaneous

Hi all, I'm trying to perform read and write I/O on a socket file descriptor received for another process via a Unix Domain Socket. In trying to understand all this I came up with a small test script that is not working for me: use strict ; use IO::Socket::INET ; my $socket = new IO::Socket::INET( PeerAddr => 'www.perl.com', PeerPort => 80, Proto => 'tcp', ) ; my $rfd = fileno($socket) ; my $rfh = new IO::Handle->fdopen($rfd, "r") ; my $wfd = fileno($socket) ; my $wfh = new IO::Handle->fdopen($wfd, "w") ; print "$rfd $rfh $wfd $wfh\n" ; print $wfh "GET / ...

  1. #1

    Default Read/Write IO on socket file descriptor

    Hi all,

    I'm trying to perform read and write I/O on a socket file descriptor
    received for another process via a Unix Domain Socket. In trying to
    understand all this I came up with a small test script that is not
    working for me:


    use strict ;
    use IO::Socket::INET ;

    my $socket = new IO::Socket::INET(
    PeerAddr => 'www.perl.com',
    PeerPort => 80,
    Proto => 'tcp',
    ) ;

    my $rfd = fileno($socket) ;
    my $rfh = new IO::Handle->fdopen($rfd, "r") ;
    my $wfd = fileno($socket) ;
    my $wfh = new IO::Handle->fdopen($wfd, "w") ;

    print "$rfd $rfh $wfd $wfh\n" ;
    print $wfh "GET / HTTP/1.0\n\n" ;
    print "Sent GET...\n" ;
    my $line = <$rfh> ;
    print $line ;


    Should this work? It seems as though printing to $wfh
    does nothing, and then the <$rfh> is hanging.

    If this is not the way to go about this, what else can I do
    to perform read AND write I/O on a socket file descriptor?

    I'm using Perl 5.6.1 on Linux RH 7.1

    Thanks,

    Patrick LeBoutillier
    Patrick LeBoutillier Guest

  2. #2

    Default Re: Read/Write IO on socket file descriptor

    [email]patrick_leboutillierhotmail.com[/email] (Patrick LeBoutillier) wrote in
    news:154121e6.0307200548.415e0d21posting.google.c om:
    > Hi all,
    >
    > I'm trying to perform read and write I/O on a socket file descriptor
    > received for another process via a Unix Domain Socket. In trying to
    > understand all this I came up with a small test script that is not
    > working for me:
    I am no expert so please take what I say with a grain of salt.
    > use strict ;
    > use IO::Socket::INET ;
    >
    > my $socket = new IO::Socket::INET(
    > PeerAddr => 'www.perl.com',
    > PeerPort => 80,
    > Proto => 'tcp',
    > ) ;
    >
    > my $rfd = fileno($socket) ;
    > my $rfh = new IO::Handle->fdopen($rfd, "r") ;
    > my $wfd = fileno($socket) ;
    > my $wfh = new IO::Handle->fdopen($wfd, "w") ;
    $wfh->autoflush(1);
    > print "$rfd $rfh $wfd $wfh\n" ;
    > print $wfh "GET / HTTP/1.0\n\n" ;
    > print "Sent GET...\n" ;
    > my $line = <$rfh> ;
    > print $line ;

    Also, I am not sure why you are creating $rfh and $wfh. $socket can be read
    from and written to using regular Perl syntax:

    #! C:/Perl/bin/perl.exe

    use strict;
    use warnings;

    use IO::Socket::INET;

    my $socket = new IO::Socket::INET(
    PeerAddr => 'www.perl.com',
    PeerPort => 80,
    Proto => 'tcp');

    die "Cannot open connection: $!\n" unless $socket;

    print $socket "GET / HTTP/1.0\n\n";
    print "Sent GET...\n";
    my $line = <$socket>;
    close $socket;

    print $line, "\n";

    __END__

    Sinan.
    --
    A. Sinan Unur
    [email]asu1c-o-r-n-e-l-l.edu[/email]
    Remove dashes for address
    Spam bait: mailto:uceftc.gov
    A. Sinan Unur Guest

Similar Threads

  1. Unable to read/write to .ini file using .dll in webservice
    By Rhydian Coombs via .NET 247 in forum ASP.NET Web Services
    Replies: 1
    Last Post: April 3rd, 01:25 AM
  2. File system get auto change from read-write to read-oly
    By RC in forum Linux / Unix Administration
    Replies: 1
    Last Post: October 23rd, 10:51 PM
  3. Help with IO::socket simultaneous read and write
    By Steve D in forum PERL Miscellaneous
    Replies: 0
    Last Post: September 4th, 04:05 AM
  4. read/write binary file
    By Stephen Richardson in forum ASP.NET Web Services
    Replies: 3
    Last Post: August 13th, 06:56 AM
  5. Managing read/write socket without polling
    By Peter Ammon in forum UNIX Programming
    Replies: 3
    Last Post: July 8th, 08:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139