Server
    
            
            in package
            
        
    
            
            implements
                            LoggerAwareInterface,                             Stringable                    
    
            
            uses
                            ListenerTrait,                             SendMethodsTrait,                             StringableTrait                    
    
WebSocket\Server class.
Entry class for WebSocket server.
Table of Contents
Interfaces
- LoggerAwareInterface
- Describes a logger-aware instance.
- Stringable
Constants
- GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
Properties
- $connections : array<string|int, mixed>
- $frameSize : int
- $listeners : array<string|int, mixed>
- $logger : LoggerInterface
- $middlewares : array<string|int, mixed>
- $port : int
- $running : bool
- $scheme : string
- $server : SocketServer|null
- $streamFactory : StreamFactory
- $streams : StreamCollection|null
- $timeout : int
Methods
- __construct() : mixed
- __toString() : string
- Get string representation of instance.
- addMiddleware() : self
- Add a middleware.
- binary() : Binary
- Send binary message.
- close() : Close
- Tell the socket to close.
- disconnect() : void
- Disconnect all connections and stop server.
- getConnectionCount() : int
- Number of currently connected clients.
- getFrameSize() : int
- Get frame size.
- getPort() : int
- Get socket port number.
- getScheme() : string
- Get connection scheme.
- getTimeout() : int
- Get timeout.
- isRunning() : bool
- If server is running (accepting connections and messages).
- isSsl() : string
- Get connection scheme.
- 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.
- send() : Message
- Send message (broadcast to all connected clients).
- setFrameSize() : self
- Set frame size.
- setLogger() : void
- Set logger.
- setStreamFactory() : self
- Set stream factory to use.
- setTimeout() : self
- Set timeout.
- start() : void
- Start server listener.
- stop() : void
- Stop server listener (resumable).
- text() : Text
- Send text message.
- acceptSocket() : void
- createSocketServer() : void
- detachUnconnected() : void
- performHandshake() : ServerRequest
- stringable() : string
- dispatch() : void
Constants
GUID
    private
        mixed
    GUID
    = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
    
    
    
Properties
$connections
    private
        array<string|int, mixed>
    $connections
     = []
    
    
    
$frameSize
    private
        int
    $frameSize
     = 4096
    
    
    
$listeners
    private
        array<string|int, mixed>
    $listeners
     = []
    
    
    
$logger
    private
        LoggerInterface
    $logger
    
    
    
    
$middlewares
    private
        array<string|int, mixed>
    $middlewares
     = []
    
    
    
$port
    private
        int
    $port
    
    
    
    
$running
    private
        bool
    $running
     = false
    
    
    
$scheme
    private
        string
    $scheme
    
    
    
    
$server
    private
        SocketServer|null
    $server
     = null
    
    
    
$streamFactory
    private
        StreamFactory
    $streamFactory
    
    
    
    
$streams
    private
        StreamCollection|null
    $streams
     = null
    
    
    
$timeout
    private
        int
    $timeout
     = 60
    
    
    
Methods
__construct()
    public
                    __construct([int $port = 80 ][, bool $ssl = false ]) : mixed
    Parameters
- $port : int = 80
- 
                    Socket port to listen to 
- $ssl : bool = false
Tags
__toString()
Get string representation of instance.
    public
                    __toString() : string
    Return values
string —String representation
addMiddleware()
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
disconnect()
Disconnect all connections and stop server.
    public
                    disconnect() : void
    getConnectionCount()
Number of currently connected clients.
    public
                    getConnectionCount() : int
    Return values
int —Connection count
getFrameSize()
Get frame size.
    public
                    getFrameSize() : int
    Return values
int —Frame size in bytes
getPort()
Get socket port number.
    public
                    getPort() : int
    Return values
int —port
getScheme()
Get connection scheme.
    public
                    getScheme() : string
    Return values
string —scheme
getTimeout()
Get timeout.
    public
                    getTimeout() : int
    Return values
int —Timeout in seconds
isRunning()
If server is running (accepting connections and messages).
    public
                    isRunning() : bool
    Return values
boolisSsl()
Get connection scheme.
    public
                    isSsl() : string
    Return values
string —scheme
onBinary()
    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
send()
Send message (broadcast to all connected clients).
    public
                    send(Message $message) : Message
    Parameters
- $message : Message
- 
                    Message to send 
Return values
MessagesetFrameSize()
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 
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 server listener.
    public
                    start() : void
    Tags
stop()
Stop server listener (resumable).
    public
                    stop() : void
    text()
Send text message.
    public
                    text(string $message) : Text
    Parameters
- $message : string
- 
                    Content as string. 
Return values
Text —instance
acceptSocket()
    protected
                    acceptSocket(SocketServer $socket) : void
    Parameters
- $socket : SocketServer
createSocketServer()
    protected
                    createSocketServer() : void
    detachUnconnected()
    protected
                    detachUnconnected() : void
    performHandshake()
    protected
                    performHandshake(Connection $connection) : ServerRequest
    Parameters
- $connection : Connection
Return values
ServerRequeststringable()
    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> = []