\SocketServerConnectionTransmitter.php
Wrapper for stream functionality.
This package provides data integrity to stream functionality, particularly useful for sockets.
PHP version 5
- Author
- Vasil Rangelov
- Category
- Net
- Copyright
- 2011 Vasil Rangelov
- License
- LGPL License 2.1
- Link
- http://netrouteros.sourceforge.net/
- Package
- PEAR2_Net_Transmitter
- Version
- 1.0.0a1
\PEAR2\Net\Transmitter\SocketServerConnectionTransmitter
A transmitter for connections to a socket server.
This is a convinience wrapper for functionality of socket server connections. Used to ensure data integrity. Server handling is not part of the class in order to allow its usage as part of various server implementations (e.g. fork and/or sequential).
- Parent(s)
- \PEAR2\Net\Transmitter\StreamTransmitter
- See
- \PEAR2\Net\Transmitter\Client
- Author
- Vasil Rangelov
- Category
- Net
- License
- LGPL License 2.1
- Link
- http://netrouteros.sourceforge.net/
Properties
bool
$persist= ''
- Type
- bool
- Inherited_from
- \PEAR2\Net\Transmitter\StreamTransmitter::$persist
resource
$stream= ''
- Type
- resource
- Inherited_from
- \PEAR2\Net\Transmitter\StreamTransmitter::$stream
Methods
__construct(
resource $server, float $timeout
=
null
)
:
void
Creates a new connection with the specified options.
Name | Type | Description |
---|---|---|
$server | resource | A socket server, created with {@link stream_socket_server()}. |
$timeout | float | The timeout for the connection. |
__destruct(
)
:
void
Closes the opened stream, unless it's a persistent one.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::__destruct()close(
)
:
bool
Closes the opened stream, even if it is a persistent one.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::close()Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |
createException(
string $message, int $code
=
0
)
:
\PEAR2\Net\Transmitter\SocketException
Creates a new exception.
Creates a new exception. Used by the rest of the functions in this class.
Name | Type | Description |
---|---|---|
$message | string | The exception message. |
$code | int | The exception code. |
Type | Description |
---|---|
\PEAR2\Net\Transmitter\SocketException | The exception to then be thrown. |
getPeerIP(
)
:
string
Gets the IP address of the connected client.
Type | Description |
---|---|
string | The IP address of the connected client. |
getPeerPort(
)
:
int
Gets the port of the connected client.
Type | Description |
---|---|
int | The port of the connected client. |
isAcceptingData(
)
:
bool
Checks whether the wrapped stream can be written to without a block.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::isAcceptingData()Type | Description |
---|---|
bool | TRUE if the wrapped stream would not block on a write, FALSE otherwise. |
isAvailable(
)
:
bool
Checks whether the stream is available for operations.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::isAvailable()Type | Description |
---|---|
bool | TRUE if the stream is available, FALSE otherwise. |
isDataAwaiting(
)
:
bool
Checks whether there is data to be read from the socket.
Type | Description |
---|---|
bool | TRUE if there is data to be read, FALSE otherwise. |
isFresh(
)
:
bool
Checks whether the wrapped stream is fresh.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::isFresh()Checks whether the wrapped stream is fresh. A stream is considered fresh if there hasn't been any activity on it. Particularly useful for detecting reused persistent connections.
Type | Description |
---|---|
bool | TRUE if the socket is fresh, FALSE otherwise. |
isServer(
mixed $var
)
:
bool
Checks whether a cetain variable is a socket server.
Name | Type | Description |
---|---|---|
$var | mixed | The variable to check. |
Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |
isStream(
mixed $var
)
:
bool
Checks if a given variable is a stream resource.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::isStream()Name | Type | Description |
---|---|---|
$var | mixed | The variable to check. |
Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |
receive(
int $length, string $what
=
'data'
)
:
string
Reads from the wrapped stream to receive.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::receive()Reads from the wrapped stream to receive content as a string.
Name | Type | Description |
---|---|---|
$length | int | The number of bytes to read. |
$what | string | Descriptive string about what is being received (used in exception messages). |
Type | Description |
---|---|
string | The received content. |
receiveStream(
int $length, array $filters
=
array(, string $what
=
'stream data'
)
:
resource
Reads from the wrapped stream to receive.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::receiveStream()Reads from the wrapped stream to receive content as a stream.
Name | Type | Description |
---|---|---|
$length | int | The number of bytes to read. |
$filters | array | An array of filters to apply to the stream while receiving. Key is the filter name, value is an array of parameters for the filter. |
$what | string | Descriptive string about what is being received (used in exception messages). |
Type | Description |
---|---|
resource | The received content. |
send(
string $string
)
:
int
Sends a string over the wrapped stream.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::send()Name | Type | Description |
---|---|---|
$string | string | The string to send. |
Type | Description |
---|---|
int | The number of bytes sent. |
sendStream(
resource $stream
)
:
int
Sends a stream over the wrapped stream.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::sendStream()Name | Type | Description |
---|---|---|
$stream | resource | The stream to send. |
Type | Description |
---|---|
int | The number of bytes sent. |
setBuffer(
int $size, string $direction
=
self::DIRECTION_BOTH
)
:
bool
Sets the size of a stream's buffer.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::setBuffer()Name | Type | Description |
---|---|---|
$size | int | The desired size of the buffer, in bytes. |
$direction | string | The buffer of which direction to set. Valid values are the DIRECTION_* constants. |
Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |
setTimeout(
int $seconds, int $microseconds
=
0
)
:
bool
Sets the timeout for the stream.
Inherited from: \PEAR2\Net\Transmitter\StreamTransmitter::setTimeout()Name | Type | Description |
---|---|---|
$seconds | int | Timeout in seconds. |
$microseconds | int | Timeout in microseconds to be added to the seconds. |
Type | Description |
---|---|
bool | TRUE on success, FALSE on failure. |