Wrench\Socket\ClientSocket¶
-
class
ClientSocket¶ - Options:
- timeout_connect => int, seconds, default 2
-
constant
TIMEOUT_CONNECT¶ Default connection timeout
-
constant
TIMEOUT_SOCKET¶ Default timeout for socket operations (reads, writes)
-
constant
DEFAULT_RECEIVE_LENGTH¶
-
constant
NAME_PART_IP¶ Socket name parts
-
property
scheme¶ protected
-
property
host¶ protected
-
property
port¶ protected
-
property
socket¶ protected resource
-
property
context¶ protected
Stream context
-
property
connected¶ protected boolean
Whether the socket is connected to a server
Note, the connection may not be ready to use, but the socket is connected at least. See $handshaked, and other properties in subclasses.
-
property
firstRead¶ protected boolean
Whether the current read is the first one to the socket
-
property
name¶ protected string
The socket name according to stream_socket_get_name
-
property
options¶ protected array
-
property
protocol¶ protected Protocol
-
configure($options)¶ Parameters: - $options –
-
connect()¶ Connects to the given socket
-
reconnect()¶
-
getSocketStreamContextOptions()¶
-
getSslStreamContextOptions()¶
-
__construct($uri, $options = array())¶ URI Socket constructor
Parameters: - $uri (string) – WebSocket URI, e.g. ws://example.org:8000/chat
- $options –
-
getUri()¶ Gets the canonical/normalized URI for this socket
Returns: string
-
getName()¶
-
getHost()¶ Gets the host name
-
getPort()¶
-
getStreamContext($listen = false)¶ Gets a stream context
Parameters: - $listen –
-
getNamePart($name, $part)¶ Gets part of the name of the socket
PHP seems to return IPV6 address/port combos like this: ::1:1234, where ::1 is the address and 1234 the port So, the part number here is either the last : delimited section (the port) or all the other sections (the whole initial part, the address).
Parameters: - $name (string) – (from $this->getName() usually)
- $part –
Returns: string
-
getIp()¶ Gets the IP address of the socket
Returns: string
-
getLastError()¶ Get the last error that occurred on the socket
Returns: int|string
-
isConnected()¶ Whether the socket is currently connected
Returns: boolean
-
disconnect()¶ Disconnect the socket
Returns: void
-
getResource()¶
-
getResourceId()¶
-
send($data)¶ Parameters: - $data (unknown_type) –
Returns: boolean|int The number of bytes sent or false on error
-
receive($length = self::DEFAULT_RECEIVE_LENGTH)¶ Recieve data from the socket
Parameters: - $length (int) –
Returns: string
-
configureProtocol()¶ Configures the protocol option