NAME

IOMux::HTTP::Client - HTTP client implementation

INHERITANCE

IOMux::HTTP::Client
  is a IOMux::HTTP
  is a IOMux::Net::TCP
  is a IOMux::Handler::Read
  is a IOMux::Handler

  IOMux::Net::TCP also extends IOMux::Handler::Write
  is a IOMux::Handler::Write
  is a IOMux::Handler

SYNOPSIS

my $socket = IO::Socket::INET->new(@sock_params);
my $socket = IO::Socket::SSL->new(@sock_params);
my $client = IOMux::HTTP::Client->new(socket => $socket);
$mux->add($client);

# or in one go:
my $client = $mux->add(IOMux::HTTP::Client->new(@sock_params));

DESCRIPTION

Handles a HTTP/1.1 connection to a HTTP server, for IOMux based applications only. The multiplexer allows one application to sent requests and receive answers from multiple servers in parallel in one single process.

WARNING: Writing event driven programs in a challenge.

METHODS

Constructors

IOMux::HTTP::Client->new(OPTIONS) See "Constructors" in IOMux::HTTP
IOMux::HTTP::Client->open(MODE, WHAT, OPTIONS) See "Constructors" in IOMux::Handler
IOMux::HTTP::Client->open(MODE, WHAT, OPTIONS) See "Constructors" in IOMux::Handler

Accessors

$obj->fh See "Accessors" in IOMux::Handler
$obj->fh See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->msgsSent
$obj->mux See "Accessors" in IOMux::Handler
$obj->mux See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->readSize([INTEGER]) See "Accessors" in IOMux::Handler::Read
$obj->socket See "Accessors" in IOMux::Net::TCP
$obj->startTime See "Accessors" in IOMux::HTTP
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->writeSize([INTEGER]) See "Accessors" in IOMux::Handler::Write

User interface

Connection

$obj->close([CALLBACK]) See "Connection" in IOMux::Handler
$obj->close([CALLBACK]) See "Connection" in IOMux::Handler
$obj->shutdown((0|1|2)) See "Connection" in IOMux::Net::TCP
$obj->timeout([TIMEOUT]) See "Connection" in IOMux::Handler
$obj->timeout([TIMEOUT]) See "Connection" in IOMux::Handler

Reading

$obj->readline(CALLBACK) See "Reading" in IOMux::Handler::Read
$obj->slurp(CALLBACK) See "Reading" in IOMux::Handler::Read

Writing

$obj->print(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->printf(FORMAT, PARAMS) See "Writing" in IOMux::Handler::Write
$obj->say(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->write(SCALAR, [MORE]) See "Writing" in IOMux::Handler::Write

Multiplexer

Connection

$obj->mux_init(MUX, [HANDLER]) See "Connection" in IOMux::Handler
$obj->mux_init(MUX, [HANDLER]) See "Connection" in IOMux::Handler
$obj->mux_remove See "Connection" in IOMux::Handler
$obj->mux_remove See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::Handler

Reading

$obj->mux_eof See "Multiplexer" in IOMux::Net::TCP
$obj->mux_except_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_except_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_input(BUFFER) See "Reading" in IOMux::Handler::Read
$obj->mux_read_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_read_flagged(FILENO) See "Reading" in IOMux::Handler

Writing

$obj->mux_outbuffer_empty See "Writing" in IOMux::Handler::Write
$obj->mux_output_waiting See "Writing" in IOMux::Handler::Write
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler

Service

Helpers

$obj->extractSocket(HASH)
IOMux::HTTP::Client->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->extractSocket(HASH)
IOMux::HTTP::Client->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler

HTTP protocol

$obj->closeConnection See "HTTP protocol" in IOMux::HTTP
$obj->sendMessage(MESSAGE, CALLBACK) See "HTTP protocol" in IOMux::HTTP
$obj->sendRequest(REQUEST, CALLBACK, SESSION)

Send the request to the server. When the whole message has been sent, the CALLBACK will be called. You may send more REQUESTS in a row, which will be handled in-order by the server.

See a detailed example farther below in this man-page.

DETAILS

Coding examples

Often, HTTP interactions are rather stateless: simply requesting some files to be downloaded. However, more and more applications use HTTP as generic transport protocol with more complex message interchange. This module cleanly supports state transitions. See them as tasks to perform.

Any client implementation starts off like this

my $server = "localhost:8081";

# You may also choose IOMux::Select or other
# multiplex instances (to be developed)
use IOMux::Poll;
my $mux    = IOMux::Poll->new;

use IOMux::HTTP::Client;
my $client = IOMux::HTTP::Client->new(PeerAddr => $server);
$mux->add($client);

# A session HASH (you may create a nice object around it)
# will be passed from step to step.
my $session = {};

# Take the first step
step1($client, $session);

# You may initiate multiple clients and start many different steps
# until you start the loop.
$mux->loop;

# The loop is left when all connections have closed
exit 0;

# Now here comes the implementation as shown in the examples below.

SEE ALSO

This module is part of IOMux-HTTP distribution version 0.11, built on January 27, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IOMux", and "IOMux::HTTP".

Please post questions or ideas to perl@overmeer.net

LICENSE

Copyrights 2011 by Mark Overmeer. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html