Documentation

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

$middlewares

private array<string|int, mixed> $middlewares = []

$running

private bool $running = false

$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
throws
InvalidArgumentException

If invalid port provided

__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
self

binary()

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
bool

isSsl()

Get connection scheme.

public isSsl() : string
Return values
string

scheme

onBinary()

public onBinary(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onClose()

public onClose(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onConnect()

public onConnect(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onDisconnect()

public onDisconnect(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onError()

public onError(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onPing()

public onPing(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onPong()

public onPong(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onText()

public onText(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

onTick()

public onTick(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

ping()

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
Message

setFrameSize()

Set frame size.

public setFrameSize(int $frameSize) : self
Parameters
$frameSize : int

Frame size in bytes

Tags
throws
InvalidArgumentException

If invalid frameSize provided

Return values
self

setLogger()

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
self

setTimeout()

Set timeout.

public setTimeout(int $timeout) : self
Parameters
$timeout : int

Timeout in seconds

Tags
throws
InvalidArgumentException

If invalid timeout provided

Return values
self

start()

Start server listener.

public start() : void
Tags
throws
Throwable

On low level error

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

createSocketServer()

protected createSocketServer() : void

detachUnconnected()

protected detachUnconnected() : void

stringable()

protected stringable(string $format, mixed ...$values) : string
Parameters
$format : string
$values : mixed
Return values
string

dispatch()

private dispatch(string $type[, array<string|int, mixed> $args = [] ]) : void
Parameters
$type : string
$args : array<string|int, mixed> = []

        
On this page

Search results