WebSocketConnection
履歴
| リリース | 内容 | 
|---|---|
| 20 | 追加 | 
WebSocketConnection クラス API は、WebSocketServer クラス を使って確立された WebSocket 接続を管理するのに使用します。
4D における WebSocketサーバーの実装の概要といくつかの例題については、WebSocketServer クラス を参照ください。
WebSocketConnection オブジェクト
WebSocketConnection オブジェクトは、WebSocketServer オブジェクト の WSHandler.onConnection コールバック関数が connectionHandler オブジェクトを返すと自動的に作成されます。
WebSocketConnection オブジェクトは、次のプロパティと関数を提供します:
| .handler : Object    接続を開始するのに使用された connectionHandlerオブジェクトを取得するアクセサーを格納します | 
| .id : Integer 接続の一意な識別子を格納します | 
| .send( message : Text ) .send( message : Blob ) .send( message : Object ) クライアントに メッセージ を送信します | 
| .status : Text 接続ステータスを格納します ("Closing"、"Closed"、"Connected" のいずれか)。 | 
| .terminate( { code : Integer ; message : Text } ) 接続を強制終了します | 
| .wss : 4D.WebSocketServer    接続の WebSocketServer親オブジェクトを格納します | 
.handler
.handler : Object
説明
.handler プロパティは、 接続を開始するのに使用された connectionHandler オブジェクトを取得するアクセサーを格納します。
.id
.id : Integer
説明
.id プロパティは、 接続の一意な識別子を格納します。
このプロパティは 読み取り専用 です。
.send()
.send( message : Text )
.send( message : Blob )
.send( message : Object )
| 引数 | 型 | 説明 | |
|---|---|---|---|
| message | Text / Blob / Object | -> | 送信するメッセージ | 
|
説明
.send() 関数は、 クライアントに メッセージ を送信します。
メッセージ の型によって、以下の内容が送信されます:
| 型 | 内容 | 
|---|---|
| Text | UTF-8 のテキスト | 
| BLOB | バイナリデータ | 
| Object | JSON UTF-8 のテキスト ( JSON Stringifyと同じ結果)。 | 
.status
.status : Text
説明
.status プロパティは、 接続ステータスを格納します ("Closing"、"Closed"、"Connected" のいずれか)。。
このプロパティは 読み取り専用 です。
.terminate()
.terminate( { code : Integer ; message : Text } )
| 引数 | 型 | 説明 | |
|---|---|---|---|
| code | Integer | -> | クライアントに送信されるエラーコード (> 3000 である必要があり、そうでない場合メッセージは送信されません) | 
| message | Text | -> | クライアントに送信されるエラーメッセージ | 
|
説明
.terminate() 関数は、 接続を強制終了します。
終了時に、code と message をクライアントに送信し、終了の理由を示すことができます。
.wss
.wss : 4D.WebSocketServer
説明
.wss プロパティは、 接続の WebSocketServer 親オブジェクトを格納します。
このプロパティは 読み取り専用 です。