CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Code conversion (don't want to use objects)

 



cecil_rabmere
Novice

Jun 27, 2008, 7:20 PM

Post #1 of 1 (1391 views)
Code conversion (don't want to use objects) Can't Post

Can anyone help me with the equivalent code to what i'm about to post. I don't want to use a uri object, or an io::socket object. Any help would be great. I tried building a regular socket, with no luck and used the uri object with the regular sockets. How can I replace it all with regular socket functions calls, and without using the uri object? any ideas?

note: $hostaddress is some arbitrary host address

Code
                   my $uri = URI->new($hostaddress) or print "Could not build URI for $hostaddress"; 

$host = IO::Socket::INET->new (
PeerAddr=> $uri->host,
PeerPort=> $uri->port );

die "couldn't open $hostAddr" unless $host;

binmode $host;


What I tried, with no luck. instead of $host, i'd now have HOST which is the socket i'd print to.

Code
 
my $uri = URI->new($hostaddress) or print "Could not build URI for $hostaddress";

# create the socket
socket( HOST,PF_INET,SOCK_STREAM,(getprotobyname('tcp'))[2] )
or die "Can't create a socket $!\n";

# connect to the host (whichever was specified)
connect( HOST, sockaddr_in( $uri->port, inet_aton( $uri->host ) ) )
or die "Can't connect to port $port! \n";


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives