Ask a Question related to PERL Miscellaneous, Design and Development.
-
Patrick LeBoutillier #1
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
-
Unable to read/write to .ini file using .dll in webservice
Hi, I am new to asp.net. I am creating a web service. This I havedone. The web service calls one of our .dll's. This .dll usesthe... -
File system get auto change from read-write to read-oly
I have a very strange file system with OS Redhat 7.2 The file system is read-write, but some how it randomly changes to read-only at any time.... -
Help with IO::socket simultaneous read and write
I've created an application that opens sockets (using IO::Socket) and then creates two ithreads, one that reads the socket and one that writes it. ... -
read/write binary file
I'm writing a web service which will return a string containing the contents of a binary file (converted using System.Convert.ToBase64String). When... -
Managing read/write socket without polling
I need to manage multiple socket connections to a server. Each one can have data that needs to be read or written at any time. I would like to be... -
A. Sinan Unur #2
Re: Read/Write IO on socket file descriptor
[email]patrick_leboutillier@hotmail.com[/email] (Patrick LeBoutillier) wrote in
news:154121e6.0307200548.415e0d21@posting.google.c om:
I am no expert so please take what I say with a grain of salt.> 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:
$wfh->autoflush(1);> 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 ;
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]asu1@c-o-r-n-e-l-l.edu[/email]
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
A. Sinan Unur Guest



Reply With Quote

