Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: [disign suggestion] Websocket in Rust
I've implemented a sort of a pipe to websocket protocol. It just converts std-in/outs to websocket messages and works great. If your messages have no clear boundaries, then a direct conversion works well. However if I want some logical separation of my stdout outs, then I have a problem. For example I write in Rust -
println!("Hello, world!);
A browser can receive it as a websocket message : Hello, world!\n
, however, especially on Windows, it receive it as two or more messages, like : Hello,
, world!\n
. Such separation brings a confusion in a message processing handler.
First idea is using Rust approach and prepend every message with a length counter, and finalize a websocket message sending only when the counter number bytes have been received from the pipe. Although such approach looks feasible, it will require to accumulate a message contents before sending it. The major drawback is that can be hardly possible in cases of a streaming.
Second approach, I use currently, is sending a complete message only when a certain byte appears in the stream. Such byte is \n
currently. It works great, however if a message should include carriage return itself, or I simply send binary data, the approach won't work.
Any other ideas?
2 posts - 2 participants
🏷️ rust_feed