Closed ghost closed 4 years ago
Thanks for the report @undefinedbuddy
It's likely send_websocket_message
was not fully tested and may not work. devserver
only uses it to send an empty message, so `send_websocket_message' is mostly unused.
I intended to eventually implement reloading certain individual files without a full refresh of the page, but I never got around to it so send_websocket_message
is just used to signal the page to refresh but does not send any actual data.
If you're looking to repurpose that function for other uses it may need a little fixing up to get working, I don't remember what issues were outstanding with it.
Great! I'm actually kinda stuck with a large codebase where this functionality is quite necessary. Any pointers would sure help.
Thanks for the heads up.
I don't know the details of your project, but if you need something like devserver
but with the ability to refresh individual files without reloading the page then I won't personally be adding that to devserver
soon.
I considered it, which is why send_websocket_message
exists, but it's actually a rather tricky problem that requires more thought. The current solution is fine for the majority of use cases.
If you need a custom way to send data from a server to a web page with a WebSocket do not use devserver
's implementation. In order to keep devserver
extremely lightweight only a tiny portion of the WebSocket protocol was implemented, but not enough to use it for other purposes.
I just saw a reddit post today discussing WebSocket crates which may be useful to you: https://www.reddit.com/r/rust/comments/goxm85/which_websocket_library_to_use/
Hope this helps!
Totally agreed. I'll consider the link. Thanks for the help.
Hi! I came across an issue where
send_websocket_message
is invoked and a message is sent to the connected clients. I tried sendingpath.to_path_buf().to_str().unwrap()
and it works. However, when I read the file's content (12 lines of HTML), converting it to a slice and sending it, I get the following error in the browser:Tools
Browser: Chrome 81.0.4044.138 (Official Build) (64-bit) Platform: Windows 10 OS Version 1903 (Build 18362.778) Rustup toolchain:
nightly-x86_64-pc-windows-msvc
(default & active)