Skip to main content

Crate shiguredo_websocket

Crate shiguredo_websocket 

Source
Expand description

Sans I/O な WebSocket ライブラリ

このライブラリは I/O を含まない純粋な WebSocket プロトコル実装を提供します。 HTTP/1.1 上での WebSocket 接続のみをサポートしています。

§特徴

  • Sans I/O パターンによる I/O 非依存の設計
  • クライアント・サーバー両方の接続をサポート
  • permessage-deflate 拡張 (RFC 7692) に対応
  • フレームの直接操作が可能な低レベル API

§クライアント接続

use shiguredo_websocket::{
    ClientConnectionOptions, ConnectionEvent, ConnectionOutput,
    RandomSource, WebSocketClientConnection, Timestamp,
};

// 乱数ソースの実装(実際には getrandom などを使用)
struct DemoRandom {
    counter: u32,
}

impl RandomSource for DemoRandom {
    fn masking_key(&mut self) -> [u8; 4] {
        self.counter = self.counter.wrapping_add(1);
        self.counter.to_le_bytes()
    }
    fn nonce(&mut self) -> [u8; 16] {
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    }
}

// WebSocket 接続オプション
let options = ClientConnectionOptions::new("example.com", "/");

// WebSocket 接続作成
let mut ws = WebSocketClientConnection::new(options, DemoRandom { counter: 0 });

// 接続開始
ws.connect().unwrap();

// 出力データを取得してソケットに送信
while let Some(output) = ws.poll_output() {
    if let ConnectionOutput::SendData(data) = output {
        // data をソケットに送信
    }
}

§サーバー接続

use shiguredo_websocket::{
    ServerConnectionOptions, WebSocketServerConnection,
};

// サーバー接続オプション
let options = ServerConnectionOptions::new();

// WebSocket サーバー接続作成
let mut ws = WebSocketServerConnection::new(options);

§準拠規格

  • RFC 6455 - The WebSocket Protocol
  • RFC 7692 - Compression Extensions for WebSocket

Structs§

ClientConnectionOptions
接続オプション
CloseCode
WebSocket クローズコード (RFC 6455 Section 7.4.1)
Compressor
permessage-deflate コンプレッサー
Decompressor
permessage-deflate デコンプレッサー
Error
エラー型
Extension
WebSocket 拡張ネゴシエーション結果
ExtensionParam
WebSocket 拡張パラメータ
Frame
WebSocket フレーム (RFC 6455 Section 5.2)
FrameDecoder
フレームデコーダー(Sans I/O パターン)
HandshakeRequest
ハンドシェイクリクエストビルダー
HandshakeRequestValidator
サーバー側ハンドシェイクリクエストバリデーター
HandshakeResponse
ハンドシェイクレスポンスの検証結果
HandshakeValidator
ハンドシェイクレスポンスバリデーター
PerMessageDeflate
permessage-deflate コーデック
PerMessageDeflateConfig
permessage-deflate 拡張の設定 (RFC 7692)
ServerConnectionOptions
サーバー接続オプション
ServerHandshakeRequest
サーバー側ハンドシェイクリクエスト
ServerHandshakeResponse
サーバー側ハンドシェイクレスポンス
Timestamp
Sans I/O パターンで時間を外部から与えるためのタイムスタンプ型
WebSocketClientConnection
WebSocket 接続
WebSocketServerConnection
WebSocket サーバー接続

Enums§

ConnectionEvent
接続イベント
ConnectionOutput
接続出力アクション
ConnectionState
接続状態
ErrorKind
エラーの種類
Opcode
WebSocket フレームのオペコード (RFC 6455 Section 5.2)
TimerId
タイマー ID

Traits§

ByteSliceExt
RandomSource
乱数生成のトレイト
VecExt