\Horde\SocketClient

Utility interface for establishing a stream socket client.

Summary

Methods
Properties
Constants
__construct()
__get()
__clone()
__sleep()
startTls()
close()
getStatus()
gets()
read()
write()
$connected
$secure
No constants found
_connect()
_checkStream()
$_connected
$_params
$_secure
$_stream
N/A
No private methods found
No private properties found
N/A

Properties

$connected

$connected : boolean

Is there an active connection?

Type

boolean

$secure

$secure : boolean

Is the active connection secure?

Type

boolean

$_connected

$_connected : boolean

Is there an active connection?

Type

boolean

$_params

$_params : array

Configuration parameters.

Type

array

$_secure

$_secure : boolean

Is the connection secure?

Type

boolean

$_stream

$_stream : resource

The actual socket.

Type

resource

Methods

__construct()

__construct(string  $host, integer  $port = null, integer  $timeout = 30, mixed  $secure = false, array  $context = array(), array  $params = array()) 

Constructor.

Parameters

string $host

Hostname of remote server (can contain protocol prefx).

integer $port

Port number of remote server.

integer $timeout

Connection timeout (in seconds).

mixed $secure

Security layer requested. One of:

  • false: (No encryption) [DEFAULT]
  • 'ssl': (Auto-detect SSL version)
  • 'sslv2': (Force SSL version 3)
  • 'sslv3': (Force SSL version 2)
  • 'tls': (TLS; started via protocol-level negotation over unencrypted channel)
  • 'tlsv1': (TLS version 1.x connection)
  • true: (TLS if available/necessary)
array $context

Any context parameters passed to stream_create_context().

array $params

Additional options.

Throws

\Horde\Socket\Horde\Socket\Client\Exception

__get()

__get(  $name) 

Parameters

$name

__clone()

__clone() 

This object can not be cloned.

__sleep()

__sleep() 

This object can not be serialized.

startTls()

startTls() : boolean

Start a TLS connection.

Returns

boolean —

Whether TLS was successfully started.

close()

close() 

Close the connection.

getStatus()

getStatus() : array

Returns information about the connection.

Currently returns four entries in the result array:

  • timed_out (bool): The socket timed out waiting for data
  • blocked (bool): The socket was blocked
  • eof (bool): Indicates EOF event
  • unread_bytes (int): Number of bytes left in the socket buffer

Throws

\Horde\Socket\Horde\Socket\Client\Exception

Returns

array —

Information about existing socket resource.

gets()

gets(integer  $size) : string

Returns a line of data.

Parameters

integer $size

Reading ends when $size - 1 bytes have been read, or a newline or an EOF (whichever comes first).

Throws

\Horde\Socket\Horde\Socket\Client\Exception

Returns

string —

$size bytes of data from the socket

read()

read(integer  $size) : string

Returns a specified amount of data.

Parameters

integer $size

The number of bytes to read from the socket.

Throws

\Horde\Socket\Horde\Socket\Client\Exception

Returns

string —

$size bytes of data from the socket.

write()

write(string  $data) 

Writes data to the stream.

Parameters

string $data

Data to write.

Throws

\Horde\Socket\Horde\Socket\Client\Exception

_connect()

_connect(  $host,   $port,   $timeout,   $secure,   $context,   $retries) 

Connect to the remote server.

Parameters

$host
$port
$timeout
$secure
$context
$retries

Throws

\Horde\Socket\Horde\Socket\Client\Exception

_checkStream()

_checkStream() 

Throws an exception is the stream is not a resource.

Throws

\Horde\Socket\Horde\Socket\Client\Exception