Wrench\Connection

class Connection

Represents a client connection on the server side

i.e. the Server manages a bunch of `Connection`s

property manager

protected WrenchConnectionManager

The connection manager

property socket

protected Socket

Socket object

Wraps the client connection resource

property handshaked

protected boolean

Whether the connection has successfully handshaken

property application

protected Application

The application this connection belongs to

property ip

protected string

The IP address of the client

property port

protected int

The port of the client

property headers

protected array

The array of headers included with the original request (like Cookie for example). The headers specific to the web sockets handshaking have been stripped out.

property queryParams

protected array

The array of query parameters included in the original request. The array is in the format ‘key’ => ‘value’.

property id

protected string|null

Connection ID

property payload

protected

The current payload

property options

protected array

property protocol

protected Protocol

__construct(ConnectionManager $manager, ServerClientSocket $socket, $options = array())

Constructor

Parameters:
getConnectionManager()

Gets the connection manager of this connection

Returns:WrenchConnectionManager
configure($options)
Parameters:
  • $options
configureClientInformation()
configureClientId()

Configures the client ID

We hash the client ID to prevent leakage of information if another client happens to get a hold of an ID. The secret must be lengthy, and must be kept secret for this to work: otherwise it’s trivial to search the space of possible IP addresses/ports (well, if not trivial, at least very fast).

onData($data)

Data receiver

Called by the connection manager when the connection has received data

Parameters:
  • $data (string) –
handshake($data)

Performs a websocket handshake

Parameters:
  • $data (string) –
export($data)

Returns a string export of the given binary data

Parameters:
  • $data (string) –
Returns:

string

handle($data)

Handle data received from the client

The data passed in may belong to several different frames across one or more protocols. It may not even contain a single complete frame. This method manages slotting the data into separate payload objects.

Parameters:
  • $data (string) –
handlePayload(Payload $payload)

Handle a complete payload received from the client

Parameters:
send($data, $type = Protocol::TYPE_TEXT)

Sends the payload to the connection

Parameters:
  • $data
  • $type (string) –
Returns:

boolean

process()

Processes data on the socket

close($code = Protocol::CLOSE_NORMAL)

Closes the connection according to the WebSocket protocol

Parameters:
  • $code
Returns:

boolean

log($message, $priority = 'info')

Logs a message

Parameters:
  • $message (string) –
  • $priority (string) –
getIp()

Gets the IP address of the connection

Returns:string Usually dotted quad notation
getPort()

Gets the port of the connection

Returns:int
getHeaders()

Gets the non-web-sockets headers included with the original request

Returns:array
getQueryParams()

Gets the query parameters included with the original request

Returns:array
getId()

Gets the connection ID

Returns:string
getSocket()

Gets the socket object

Returns:SocketServerClientSocket
getClientApplication()

Gets the client application

Returns:Application
configureProtocol()

Configures the protocol option