Client
    
            
            in package
            
        
    
            
            implements
                            LoggerAwareInterface,                             Stringable                    
    
            
            uses
                            ListenerTrait,                             SendMethodsTrait,                             StringableTrait                    
    
WebSocket\Client class.
Entry class for WebSocket client.
Table of Contents
Interfaces
- LoggerAwareInterface
- Describes a logger-aware instance.
- Stringable
Properties
- $connection : Connection|null
- $context : array<string|int, mixed>
- $frameSize : int
- $headers : array<string|int, mixed>
- $listeners : array<string|int, mixed>
- $logger : LoggerInterface
- $middlewares : array<string|int, mixed>
- $persistent : bool
- $running : bool
- $socketUri : Uri
- $streamFactory : StreamFactory
- $streams : StreamCollection|null
- $timeout : int
Methods
- __construct() : mixed
- __toString() : string
- Get string representation of instance.
- addHeader() : self
- Add header for handshake.
- addMiddleware() : self
- Add a middleware.
- binary() : Binary
- Send binary message.
- close() : Close
- Tell the socket to close.
- connect() : void
- Connect to server and perform upgrade.
- disconnect() : void
- Disconnect from server.
- getFrameSize() : int
- Get frame size.
- getHandshakeResponse() : Response|null
- Get Response for handshake procedure.
- getMeta() : mixed
- Get meta value on connection.
- getName() : string|null
- Get name of local socket, or null if not connected.
- getRemoteName() : string|null
- Get name of remote socket, or null if not connected.
- getTimeout() : int
- Get timeout.
- isConnected() : bool
- If Client has active connection.
- isReadable() : bool
- If Client is readable.
- isRunning() : bool
- If client is running (accepting messages).
- isWritable() : bool
- If Client is writable.
- onBinary() : self
- onClose() : self
- onConnect() : self
- onDisconnect() : self
- onError() : self
- onPing() : self
- onPong() : self
- onText() : self
- onTick() : self
- ping() : Ping
- Send ping.
- pong() : Pong
- Send unsolicited pong.
- receive() : Message
- Receive message.
- send() : Message
- Send message.
- setContext() : self
- Set connection context.
- setFrameSize() : self
- Set frame size.
- setLogger() : void
- Set logger.
- setPersistent() : self
- Set connection persistence.
- setStreamFactory() : self
- Set stream factory to use.
- setTimeout() : self
- Set timeout.
- start() : void
- Start client listener.
- stop() : void
- Stop client listener (resumable).
- text() : Text
- Send text message.
- generateKey() : string
- Generate a random string for WebSocket key.
- parseUri() : Uri
- Ensure URI instance to use in client.
- performHandshake() : Response
- Perform upgrade handshake on new connections.
- stringable() : string
- dispatch() : void
Properties
$connection
    private
        Connection|null
    $connection
     = null
    
    
    
$context
    private
        array<string|int, mixed>
    $context
     = []
    
    
    
$frameSize
    private
        int
    $frameSize
     = 4096
    
    
    
$headers
    private
        array<string|int, mixed>
    $headers
     = []
    
    
    
$listeners
    private
        array<string|int, mixed>
    $listeners
     = []
    
    
    
$logger
    private
        LoggerInterface
    $logger
    
    
    
    
$middlewares
    private
        array<string|int, mixed>
    $middlewares
     = []
    
    
    
$persistent
    private
        bool
    $persistent
     = false
    
    
    
$running
    private
        bool
    $running
     = false
    
    
    
$socketUri
    private
        Uri
    $socketUri
    
    
    
    
$streamFactory
    private
        StreamFactory
    $streamFactory
    
    
    
    
$streams
    private
        StreamCollection|null
    $streams
     = null
    
    
    
$timeout
    private
        int
    $timeout
     = 60
    
    
    
Methods
__construct()
    public
                    __construct(UriInterface|string $uri) : mixed
    Parameters
- $uri : UriInterface|string
- 
                    A ws/wss-URI 
__toString()
Get string representation of instance.
    public
                    __toString() : string
    Return values
string —String representation
addHeader()
Add header for handshake.
    public
                    addHeader(string $name, string $content) : self
    Parameters
- $name : string
- 
                    Header name 
- $content : string
- 
                    Header content 
Return values
selfaddMiddleware()
Add a middleware.
    public
                    addMiddleware(MiddlewareInterface $middleware) : self
    Parameters
- $middleware : MiddlewareInterface
Return values
selfbinary()
Send binary message.
    public
                    binary(string $message) : Binary
    Parameters
- $message : string
- 
                    Content as binary string. 
Return values
Binary —instance
close()
Tell the socket to close.
    public
                    close([int $status = 1000 ][, string $message = 'ttfn' ]) : Close
    Parameters
- $status : int = 1000
- 
                    http://tools.ietf.org/html/rfc6455#section-7.4 
- $message : string = 'ttfn'
- 
                    A closing message, max 125 bytes. 
Return values
Close —instance
connect()
Connect to server and perform upgrade.
    public
                    connect() : void
    Tags
disconnect()
Disconnect from server.
    public
                    disconnect() : void
    getFrameSize()
Get frame size.
    public
                    getFrameSize() : int
    Return values
int —Frame size in bytes
getHandshakeResponse()
Get Response for handshake procedure.
    public
                    getHandshakeResponse() : Response|null
    Return values
Response|null —Handshake.
getMeta()
Get meta value on connection.
    public
                    getMeta(string $key) : mixed
    Parameters
- $key : string
- 
                    Meta key 
Return values
mixed —Meta value
getName()
Get name of local socket, or null if not connected.
    public
                    getName() : string|null
    Return values
string|nullgetRemoteName()
Get name of remote socket, or null if not connected.
    public
                    getRemoteName() : string|null
    Return values
string|nullgetTimeout()
Get timeout.
    public
                    getTimeout() : int
    Return values
int —Timeout in seconds
isConnected()
If Client has active connection.
    public
                    isConnected() : bool
    Return values
bool —True if active connection.
isReadable()
If Client is readable.
    public
                    isReadable() : bool
    Return values
boolisRunning()
If client is running (accepting messages).
    public
                    isRunning() : bool
    Return values
boolisWritable()
If Client is writable.
    public
                    isWritable() : bool
    Return values
boolonBinary()
    public
                    onBinary(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonClose()
    public
                    onClose(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonConnect()
    public
                    onConnect(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonDisconnect()
    public
                    onDisconnect(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonError()
    public
                    onError(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonPing()
    public
                    onPing(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonPong()
    public
                    onPong(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonText()
    public
                    onText(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfonTick()
    public
                    onTick(Closure $closure) : self
    Parameters
- $closure : Closure
Return values
selfping()
Send ping.
    public
                    ping([string $message = '' ]) : Ping
    Parameters
- $message : string = ''
- 
                    Optional text as string. 
Return values
Ping —instance
pong()
Send unsolicited pong.
    public
                    pong([string $message = '' ]) : Pong
    Parameters
- $message : string = ''
- 
                    Optional text as string. 
Return values
Pong —instance
receive()
Receive message.
    public
                    receive() : Message
    Note that this operation will block reading.
Return values
Messagesend()
Send message.
    public
                    send(Message $message) : Message
    Parameters
- $message : Message
- 
                    Message to send. 
Return values
Message —Sent message
setContext()
Set connection context.
    public
                    setContext(array<string|int, mixed> $context) : self
    Parameters
- $context : array<string|int, mixed>
- 
                    Context as array, see https://www.php.net/manual/en/context.php 
Return values
selfsetFrameSize()
Set frame size.
    public
                    setFrameSize(int $frameSize) : self
    Parameters
- $frameSize : int
- 
                    Frame size in bytes 
Tags
Return values
selfsetLogger()
Set logger.
    public
                    setLogger(LoggerInterface $logger) : void
    Parameters
- $logger : LoggerInterface
- 
                    Logger implementation 
setPersistent()
Set connection persistence.
    public
                    setPersistent(bool $persistent) : self
    Parameters
- $persistent : bool
- 
                    True for persistent connection. 
Return values
self —.
setStreamFactory()
Set stream factory to use.
    public
                    setStreamFactory(StreamFactory $streamFactory) : self
    Parameters
- $streamFactory : StreamFactory
Return values
selfsetTimeout()
Set timeout.
    public
                    setTimeout(int $timeout) : self
    Parameters
- $timeout : int
- 
                    Timeout in seconds 
Tags
Return values
selfstart()
Start client listener.
    public
                    start() : void
    Tags
stop()
Stop client listener (resumable).
    public
                    stop() : void
    text()
Send text message.
    public
                    text(string $message) : Text
    Parameters
- $message : string
- 
                    Content as string. 
Return values
Text —instance
generateKey()
Generate a random string for WebSocket key.
    protected
                    generateKey() : string
    Return values
string —Random string
parseUri()
Ensure URI instance to use in client.
    protected
                    parseUri(UriInterface|string $uri) : Uri
    Parameters
- $uri : UriInterface|string
- 
                    A ws/wss-URI 
Tags
Return values
UriperformHandshake()
Perform upgrade handshake on new connections.
    protected
                    performHandshake(Uri $uri) : Response
    Parameters
- $uri : Uri
Tags
Return values
Responsestringable()
    protected
                    stringable(string $format, mixed ...$values) : string
    Parameters
- $format : string
- $values : mixed
Return values
stringdispatch()
    private
                    dispatch(string $type[, array<string|int, mixed> $args = [] ]) : void
    Parameters
- $type : string
- $args : array<string|int, mixed> = []