Connection
in package
implements
LoggerAwareInterface, Stringable
uses
SendMethodsTrait, StringableTrait
WebSocket\Connection class.
A client/server connection, wrapping socket stream.
Table of Contents
Interfaces
- LoggerAwareInterface
- Describes a logger-aware instance.
- Stringable
Properties
- $closed : bool
- $frameSize : int
- $handshakeRequest : Request|null
- $handshakeResponse : Response|null
- $httpHandler : HttpHandler
- $localName : string
- $logger : LoggerInterface
- $messageHandler : MessageHandler
- $meta : array<string|int, mixed>
- $middlewareHandler : MiddlewareHandler
- $remoteName : string
- $stream : SocketStream
- $timeout : int
Methods
- __construct() : mixed
- __destruct() : mixed
- __toString() : string
- addMiddleware() : self
- Add a middleware.
- binary() : Binary
- Send binary message.
- close() : Close
- Tell the socket to close.
- closeRead() : self
- Close connection stream reading.
- closeWrite() : self
- Close connection stream writing.
- disconnect() : self
- Close connection stream.
- getFrameSize() : int
- Get frame size.
- getHandshakeRequest() : Request|null
- getHandshakeResponse() : Response|null
- 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 connected to stream.
- isReadable() : bool
- If connection is readable.
- isWritable() : bool
- If connection is writable.
- ping() : Ping
- Send ping.
- pong() : Pong
- Send unsolicited pong.
- pullHttp() : Message
- pullMessage() : Message
- pushHttp() : Message
- pushMessage() : Message
- send() : Message
- setFrameSize() : self
- Set frame size.
- setHandshakeRequest() : self
- setHandshakeResponse() : self
- setLogger() : void
- Set logger.
- setMeta() : void
- Set meta value on connection.
- setTimeout() : self
- Set time out on connection.
- text() : Text
- Send text message.
- tick() : void
- Tick operation on connection.
- stringable() : string
- throwException() : never
Properties
$closed
private
bool
$closed
= false
$frameSize
private
int
$frameSize
= 4096
$handshakeRequest
private
Request|null
$handshakeRequest
= null
$handshakeResponse
private
Response|null
$handshakeResponse
= null
$httpHandler
private
HttpHandler
$httpHandler
$localName
private
string
$localName
$logger
private
LoggerInterface
$logger
$messageHandler
private
MessageHandler
$messageHandler
$meta
private
array<string|int, mixed>
$meta
= []
$middlewareHandler
private
MiddlewareHandler
$middlewareHandler
$remoteName
private
string
$remoteName
$stream
private
SocketStream
$stream
$timeout
private
int
$timeout
= 60
Methods
__construct()
public
__construct(SocketStream $stream, bool $pushMasked, bool $pullMaskedRequired[, bool $ssl = false ]) : mixed
Parameters
- $stream : SocketStream
- $pushMasked : bool
- $pullMaskedRequired : bool
- $ssl : bool = false
__destruct()
public
__destruct() : mixed
__toString()
public
__toString() : string
Return values
stringaddMiddleware()
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
closeRead()
Close connection stream reading.
public
closeRead() : self
Return values
self —.
closeWrite()
Close connection stream writing.
public
closeWrite() : self
Return values
self —.
disconnect()
Close connection stream.
public
disconnect() : self
Return values
self —.
getFrameSize()
Get frame size.
public
getFrameSize() : int
Return values
int —Frame size in bytes
getHandshakeRequest()
public
getHandshakeRequest() : Request|null
Return values
Request|nullgetHandshakeResponse()
public
getHandshakeResponse() : Response|null
Return values
Response|nullgetMeta()
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 connected to stream.
public
isConnected() : bool
Return values
boolisReadable()
If connection is readable.
public
isReadable() : bool
Return values
boolisWritable()
If connection is writable.
public
isWritable() : bool
Return values
boolping()
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
pullHttp()
public
pullHttp() : Message
Return values
MessagepullMessage()
public
pullMessage() : Message
Return values
MessagepushHttp()
public
pushHttp(Message $message) : Message
Parameters
- $message : Message
Return values
MessagepushMessage()
public
pushMessage(Message $message) : Message
Parameters
- $message : Message
Return values
Messagesend()
public
send(Message $message) : Message
Parameters
- $message : Message
Return values
MessagesetFrameSize()
Set frame size.
public
setFrameSize(int $frameSize) : self
Parameters
- $frameSize : int
-
Frame size in bytes.
Return values
self —.
setHandshakeRequest()
public
setHandshakeRequest(Request $request) : self
Parameters
- $request : Request
Return values
selfsetHandshakeResponse()
public
setHandshakeResponse(Response $response) : self
Parameters
- $response : Response
Return values
selfsetLogger()
Set logger.
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
-
Logger implementation
setMeta()
Set meta value on connection.
public
setMeta(string $key, mixed $value) : void
Parameters
- $key : string
-
Meta key
- $value : mixed
-
Meta value
setTimeout()
Set time out on connection.
public
setTimeout(int $seconds) : self
Parameters
- $seconds : int
-
Timeout part in seconds
Return values
self —.
text()
Send text message.
public
text(string $message) : Text
Parameters
- $message : string
-
Content as string.
Return values
Text —instance
tick()
Tick operation on connection.
public
tick() : void
stringable()
protected
stringable(string $format, mixed ...$values) : string
Parameters
- $format : string
- $values : mixed
Return values
stringthrowException()
protected
throwException(Throwable $e) : never
Parameters
- $e : Throwable