Gossamer Forum
Home : General : Perl Programming :

Code conversion (don't want to use objects)

Quote Reply
Code conversion (don't want to use objects)
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";