Guide Home
POD Home



Sloop::Other allows for connections to other TCP servers as a client. Like Sloop::Client, it must be combined with Sloop::Socket::Standard or Sloop::Socket::TLS, which is the purpose of Sloop::Other::Regular and Sloop::Other::Secure. However, both these inherit this API.

You may use a Secure Other with a normal Server and vice versa.

To be useful, the object must first be passed to $sloop->connectOther(), where $sloop is a Sloop::Server object.


 use Sloop::Other
 my $other = Sloop::Other->new (
     debug => (optional) see Sloop::Base
     dest_addr => (REQUIRED) scalar IP address
     dest_port => Integer port number, required for INET connections.
     id => (optional) see Sloop::Base
     incoming => (REQUIRED) sub or array ref
     logger => (REQUIRED) Sloop::Logger object
     max_recv => (optional) see Sloop::Connection
     max_send => (optional) see Sloop::Connection
     proto => (optional) 1 (Unix local) or (INET IPv) 4 or 6; default 4.

Parameters not described in a base class (Sloop::Base and Sloop::Connection), and/or requiring further explication here are listed below.


This has the same significance it does for other client objects attached to the server (see Sloop::Constants), but because the $other object is not created by the server you must set this value yourself; normal clients have it set the same as the 'debug' argument to Sloop::Server::new.


An IP address (not a domain name) in string form, e.g. "" for IPv4 or "ff:80ab::1234:2015::dead:beef" for IPv6.


The port number to connect to.


If not defined, the package name ("Sloop::Other") is used.


Either a subroutine reference, or a reference to an array of sub refs. If the latter, when required the first sub in the array will be used. If it returns > 0, it will then be shifted off the front of the array.

The sub will be fired when a message is received. It is passed three arguments, the Sloop::Other object, a reference to a scalar containing the message, and the length of the message in bytes. If it returns -1, the connection will be closed and the object is subsequently not usable for communication.

 $other->{incoming} = sub {
     my ($self, $msgref, $bytes) = (shift, shift, shift);
     # Acknowledge reciept to the other party.
     $self->message(\"Recieved $bytes bytes.");
     return 1;

If the other party is also an HTTP server, you can use Sloop::Client::Request::getHeaders() to parse the response headers, just remember to remove the first line (status) first.


This is 1 for AF_LOCAL sockets or else the IP version to use; the default is 4. It does not have to be the same as the Sloop::Server.



Queues data to be sent to the remote server. Sloop does not do any processing of this. This is a non-blocking call; it queues data to be sent and does not wait for its transmission.

$dataref is a reference to a scalar containing the data. It may be of any sort (i.e., text or binary).


You can call this if you want to arbitrarily render the connection defunct but ok() still returns true. It gets called by the server on certain errors, or via the destructor (actually, via the Sloop::Base destructor, although it is implemented in one of the Sloop::Socket classes).

"Defunct" means you cannot use this object to send or receive messages anymore.