PHP Class Swoole\Protocol\WebSocket

Inheritance: extends HttpServer
显示文件 Open project: matyhtf/swoole_framework Class Usage Examples

Public Properties

Property Type Description
$connections
$frame_list
$heart_time 数据包最大长度,超过此长度会被认为是非法请求
$keepalive 600s life time
$max_connect
$max_frame_size

Public Methods

Method Description
afterResponse ( Request $request, Response $response ) Clean and fire onWsConnect().
cleanBuffer ( $fd ) 清理连接缓存区
cleanConnection ( ) clean all connection
close ( integer $fd, integer $code = self::CLOSE_NORMAL, string $reason = '' ) : boolean Close a connection.
doHandshake ( Request $request, Response $response ) : boolean Do the handshake.
newFrame ( string $message, integer $opcode = self::OPCODE_TEXT_FRAME, boolean $end = true ) : integer Write a frame.
onClose ( $serv, $client_id, $from_id )
onConnect ( $serv, $fd, $from_id )
onEnter ( $client_id )
onExit ( $client_id ) : mixed 客户端退出
onHttpRequest ( Request $request ) : Response Produce response for Http request.
onMessage ( $client_id, $message ) : mixed 收到消息
onReceive ( $server, $fd, $from_id, $data ) Read a frame.
onRequest ( Request $request ) : Response Request come
onWebSocketRequest ( Request $request ) : Response Produce response for WebSocket request.
onWsConnect ( $client_id, $request ) Called on WebSocket connection established.
opcodeSwitch ( $client_id, &$ws ) opcode switch
parseFrame ( &$buffer ) : array | boolean 解析数据帧 返回false表示解析失败,需要关闭此连接
send ( integer $client_id, string $message, integer $opcode = self::OPCODE_TEXT_FRAME, boolean $end = true ) : boolean Send a message.

Protected Methods

Method Description
parseMessage ( $ws )

Method Details

afterResponse() public method

Clean and fire onWsConnect().
public afterResponse ( Request $request, Response $response )
$request Swoole\Request
$response Swoole\Response

cleanBuffer() public method

清理连接缓存区
public cleanBuffer ( $fd )
$fd

cleanConnection() public method

clean all connection
public cleanConnection ( )

close() public method

Close a connection.
public close ( integer $fd, integer $code = self::CLOSE_NORMAL, string $reason = '' ) : boolean
$fd integer
$code integer
$reason string Reason.
return boolean

doHandshake() public method

Do the handshake.
public doHandshake ( Request $request, Response $response ) : boolean
$request Swoole\Request
$response Swoole\Response
return boolean

newFrame() public method

Write a frame.
public newFrame ( string $message, integer $opcode = self::OPCODE_TEXT_FRAME, boolean $end = true ) : integer
$message string Message.
$opcode integer Opcode.
$end boolean
return integer

onClose() public method

public onClose ( $serv, $client_id, $from_id )

onConnect() public method

public onConnect ( $serv, $fd, $from_id )

onEnter() public method

public onEnter ( $client_id )
$client_id

onExit() public method

客户端退出
public onExit ( $client_id ) : mixed
$client_id
return mixed

onHttpRequest() public method

Produce response for Http request.
public onHttpRequest ( Request $request ) : Response
$request Swoole\Request
return Swoole\Response

onMessage() abstract public method

收到消息
abstract public onMessage ( $client_id, $message ) : mixed
$client_id
$message
return mixed

onReceive() public method

Read a frame.
public onReceive ( $server, $fd, $from_id, $data )

onRequest() public method

Request come
public onRequest ( Request $request ) : Response
$request Swoole\Request
return Swoole\Response

onWebSocketRequest() public method

Produce response for WebSocket request.
public onWebSocketRequest ( Request $request ) : Response
$request Swoole\Request
return Swoole\Response

onWsConnect() public method

Called on WebSocket connection established.
public onWsConnect ( $client_id, $request )
$client_id
$request

opcodeSwitch() public method

opcode switch
public opcodeSwitch ( $client_id, &$ws )
$client_id
$ws

parseFrame() public method

解析数据帧 返回false表示解析失败,需要关闭此连接
public parseFrame ( &$buffer ) : array | boolean
$buffer
return array | boolean

parseMessage() protected method

protected parseMessage ( $ws )

send() public method

Send a message.
public send ( integer $client_id, string $message, integer $opcode = self::OPCODE_TEXT_FRAME, boolean $end = true ) : boolean
$client_id integer
$message string Message.
$opcode integer Opcode.
$end boolean Whether it is the last frame of the message.
return boolean

Property Details

$connections public_oe property

public $connections

$frame_list public_oe property

public $frame_list

$heart_time public_oe property

数据包最大长度,超过此长度会被认为是非法请求
public $heart_time

$keepalive public_oe property

600s life time
public $keepalive

$max_connect public_oe property

public $max_connect

$max_frame_size public_oe property

public $max_frame_size