\PHP\WebSocketSocketClient

Class representing a WebSocket client.

Summary

Methods
Properties
Constants
__construct()
send()
set()
get()
disconnect()
performHandshake()
__toString()
$instances
$server
$id
$socket
$state
$ip
$port
$lastRecieveTime
$lastSendTime
$data
STATE_CONNECTING
STATE_OPEN
STATE_CLOSED
No protected methods found
No protected properties found
N/A
parseRequestHeader()
No private properties found
N/A

Constants

STATE_CONNECTING

STATE_CONNECTING = 0

User is connecting, handshake not yet performed.

STATE_OPEN

STATE_OPEN = 1

Connection is valid.

STATE_CLOSED

STATE_CLOSED = 2

Connection has been closed.

Properties

$instances

$instances : integer

Number of instances created.

Type

integer

$id

$id : integer

Client id.

This starts from one and is incremented for every connecting user.

Type

integer

$socket

$socket : resource

Client socket.

Type

resource

$state

$state : integer

Client state.

One of SocketClient::STATE_.. constants.

Type

integer

$ip

$ip : string

The ip of the client.

Type

string

$port

$port : integer

The port of the client.

Type

integer

$lastRecieveTime

$lastRecieveTime : integer

The time data was last recieved from the client.

Type

integer

$lastSendTime

$lastSendTime : integer

Last time data was sent to this client.

Type

integer

$data

$data : mixed

Any data associated with the user.

Type

mixed

Methods

__construct()

__construct(\PHP\WebSocket\SocketServer  $server, resource  $socket, integer  $state = self::STATE_CONNECTING) 

Constructor, sets the server that spawned the client and the socket.

Parameters

\PHP\WebSocket\SocketServer $server

Parent server

resource $socket

User socket

integer $state

Initial state

send()

send(mixed  $message) 

Sends a message to the client

Parameters

mixed $message

Message to send

set()

set(string  $name, mixed  $value) 

Sets client property.

Parameters

string $name

Property name

mixed $value

Property value

get()

get(string  $name, mixed  $default = null) : mixed

Returns client property.

Parameters

string $name

Name of the property

mixed $default

Default value returned when property does not exist

Returns

mixed

disconnect()

disconnect() 

Disconnects the client.

performHandshake()

performHandshake(string  $buffer) : boolean

Does the magic handshake to begin the connection

Parameters

string $buffer

Buffer sent by the client

Throws

\Exception

If something goes wrong

Returns

boolean —

Was the handshake successful

__toString()

__toString() 

parseRequestHeader()

parseRequestHeader(string  $request) : array

Parses the request header into resource, headers and security code

Parameters

string $request

The request

Returns

array —

Array containing the resource, headers and security code