Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws can not receive text #160

Open
reison1218 opened this issue Jun 8, 2023 · 10 comments
Open

ws can not receive text #160

reison1218 opened this issue Jun 8, 2023 · 10 comments

Comments

@reison1218
Copy link

hi,thanks for your work!
i love this crate,it help me lot!
i find the ws server side can not receive text?i have check the source code.
because the trait Remote's function "fn receive(&self,process_data: impl FnMut(&[u8])) -> ReadStatus". u can check it on adapter.rs
i change the ws.rs, add some code for receive funciton.like this:
Message::Text(text) => {
drop(state);
process_data(text.as_bytes())
}
but this is bad way.
i know if change the trait Remote will make many change
do u have any good idea for ws support text?

@lemunozm
Copy link
Owner

lemunozm commented Jun 8, 2023

Hi @reison1218 , I'm glad you like it!

Because we need a "common" interface for all adapters, WS works in binary mode. Nevertheless, once #54 was merged (thanks to @kgraefe), I think this capability for WS can be allowed through configuration. Something like:

let conn = handler.network().connect_with(TransportConnect::Ws(WsMode::Text), addr)?;

The interface of the adapter will be the same, but the &[u8] parameters can now be interpreted internally as text, and internally the Ws adapter will send/receive the data as text.

@reison1218
Copy link
Author

thanks for your reply.
i have check the #54
so,if merge it.
we can code like this?

handler.network().listen(Transport::Ws(WsMode::Message), "0.0.0.0:3044").unwrap();

why the WsMode is Message?because user can process Text and Binary both.not just one of them.

does it possible?

@lemunozm
Copy link
Owner

lemunozm commented Jun 8, 2023

Respecting the current interface, you need to choose between one of them when creating the connection, because send()/recv() methods only knows about the buffer. You do not have enough information to know how to interpret what that buffer has

@reison1218
Copy link
Author

thanks for answer : )

@lemunozm
Copy link
Owner

Given another thought on this, maybe we could have another send_with() and recv_with() that allows to pass specific transport properties, following the structure found un #54 i.e:

send_with(data, TransportProp::Ws(WsMode::Text))

@hschneider
Copy link

Is there currently a way to receive and send text-messages or is it still work in progress?

@lemunozm
Copy link
Owner

There is no way to send text messages right now. I'm still open to review a PR with the required changes or discussing an idea. But I'm no longer adding new features in message-io, at least by now.

@hschneider
Copy link

OK - thanks for the info.

So converting bin to text and vice versa should do as a temp. workaround. This is something every end-user should be able to do.

@lemunozm
Copy link
Owner

If the server can interpret the binary message correctly, then that can be a workaround, yes

@hschneider
Copy link

hschneider commented Feb 19, 2024

It sends and receives unicode perfectly. So I see no problem even not at the server's side. Assumed, the server does not await plain text messages :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants