Websocket client based on mint-websocket and mint
At the time of writing, very few HTTP/2 server libraries support or enable HTTP/2 WebSockets by default.
Links
Summary
Functions
Returns a specification to start this module under a supervisor.
Close connection
Ws.encode |> Ws.decode
Try frame encoding
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Close connection
Ws.encode |> Ws.decode
Try frame encoding
Mint.WebSocket.encode(%{extensions: []}, :ping) Mint 在编码 WebSocket 帧时自动添加了随机掩码(Masking Key) 根据 RFC 6455,客户端发送到服务端的帧必须被掩码(Masked),而服务端发送给客户端的帧不能被掩码。掩码的目的是防止缓存污染和代理攻击。 掩码密钥的随机性确保了相同内容的不同帧在传输时二进制数据不同,防止恶意代理篡改或缓存敏感信息。
Why result changed every time??? iex(210)> Mint.WebSocket.Frame.encode(%{extensions: []}, :ping) {:ok, %{extensions: []}, <<137, 128, 215, 178, 102, 78>>} iex(211)> Mint.WebSocket.Frame.encode(%{extensions: []}, :ping) {:ok, %{extensions: []}, <<137, 128, 88, 223, 225, 101>>}