NAME
HTTunnel::Client - Client class for Apache::HTTunnel
SYNOPSIS
my $hc = new HTTunnel::Client("http://localhost/httunnel") ;
$hc->connect('tcp', $some_host, $some_port) ;
$hc->print('some request') ;
my $some_response = $hc->read(1024) ;
$ch->close() ;
DESCRIPTION
HTTunnel::Client is the client class to Apache::HTTunnel. It allows the creation of a network connection tunnelled through HTTP. All data sent and received during this connection will be transported inside normal HTTP requests.
HTTunnel::Client extends LWP::UserAgent, so all LWP::UserAgent methods are available through HTTunnel::Client.
CONSTRUCTORS
- new ( URL, [ARGS] )
-
Creates an
HTTunnel::Clientobject that will useURLto contact theApache::HTTunnelserver.ARGSare is passed directly to theLWP::UserAgentconstructor.
METHODS
- connect ( PROTO, HOST, PORT, [TIMEOUT] )
-
Asks the
Apache::HTTunnelserver to establish a connection of protocolPROTOtoHOST:PORT. An exception is thrown if an error occurs.Accepted values for
PROTOare 'tcp' and 'udp'. - print ( DATA )
-
Asks the
Apache::HTTunnelserver to writeDATAto the established remote connection. An exception is thrown if an error occurs.DATAcan be a scalar or a list, in which case the list items are concatenated together. - read ( LEN, [TIMEOUT], [LIFELINE], [LIFELINE_CUT_ACTION] )
-
Asks the
Apache::HTTunnelserver to read up toLENbytes from the established remote connection. An exception is thrown if an error occurs.When trying to read,
HTTunnel::Clientwill establish an HTTP connection to theApache::HTTunnelserver asking thatLENbytes be read. If no data is available afterTIMEOUTseconds (the default value is 15 seconds), the HTTP connection is closed by the server and thereadmethod will establish a new one. This will go on until some data or EOF is returned.Therefore
readwill return only when some (or no more) data is available to be read (like the regular read).LIFELINEcan be any valid filehandle from which one can read. If used,readwill interrupt its connection loop and executeLIFELINE_CUT_ACTIONwhen data (or EOF) is available to be read fromLIFELINE. It will then return undef.LIFELINE_CUT_ACTIONwust be a CODE ref. The default value issub {die("lifeline cut\n")}These features can be used if you want fork and to start a process that does nothing but reads and returns the data via a pipe. You can then use a second pipe to make sure the reader process terminates when the master process terminates.
Here is an example:
my $lifeline = new IO::Pipe() ; my $reader = new IO::Pipe() ; my $pid = fork() ; if ($pid){ $reader->reader() ; $lifeline->writer() ; # Read data from $reader... } else { $reader->writer() ; $reader->autoflush(1) ; $lifeline->reader() ; while (1){ my $data = $hc->read(1024, 15, $lifeline, sub {exit()}) ; exit() unless defined($data) ; print $reader $data ; } } - close ( )
-
Asks the
Apache::HTTunnelserver to close a previously established connection. - get_peer_info ( )
-
The
get_peer_infomethod returns information about the remote connection. A string containing the IP address and port number, separated by a colon (:) is returned. This method can be useful with UDP connections to validate the sender of each packet. - request_callback ( REQUEST )
-
The
request_callbackmethod is a callback method that can be used to access theHTTP::Requestobject just before it is sent. The default implementation does nothing. - response_callback ( RESPONSE )
-
The
response_callbackmethod is a callback method that can be used to access theHTTP::Responseobject just after it is received. The default implementation does nothing.
JAVA CLIENT
For those who might be interested, there is a Java version of HTTunnel::Client included in the distribution. The API is the basically the same.
BUGS
I'm sure there are some in there :)
SEE ALSO
AUTHOR
Patrick LeBoutillier, <patl@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2005 by Patrick LeBoutillier
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.