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

WebSocket : Sending a space character ( ) receives 0 #379

Closed
quentint opened this issue Dec 26, 2023 · 5 comments
Closed

WebSocket : Sending a space character ( ) receives 0 #379

quentint opened this issue Dec 26, 2023 · 5 comments

Comments

@quentint
Copy link

When sending a space character ( ) to a WebSocket, the received message is 0. I've added tests in a fork to showcase that:

https://github.com/quentint/elysia/blob/main/test/ws/message.test.ts#L5-L22

The 'Hello!' and '0' pass, but the fails. I would like to help fix this but I've looked around and didn't find where this could come from. Any pointers appreciated 😉

@ErickJ3
Copy link

ErickJ3 commented Dec 26, 2023

@quentint
Wouldn't it be appropriate to use JSON.stringify to transport messages via websocket? would avoid this type of serialization problem. I will be looking into the problem and opening a PR soon to resolve the possible serialization error. In the meantime, use JSON.stringify to transport messages via websocket

example: JSON.stringify({ message: "Hello!" })

@quentint
Copy link
Author

Thanks for your feedback!

Unfortunately I'm writing the server part of the app, but the client one uses a very old standard, and I can't change a thing about it, so I can't decide to format messages differently 😕

@ErickJ3
Copy link

ErickJ3 commented Dec 26, 2023

@quentint
in fact it is an implementation problem. I would recommend that when sending messages on the websocket channel you ignore completely empty messages. in the implementation somehow it is converting the total empty space to 0

@quentint
Copy link
Author

But I cannot differentiate spaces wrongfully converted to 0, and actual zeroes.

What do you mean by an implementation problem? Did you locate it?

@SaltyAom
Copy link
Member

SaltyAom commented Jan 1, 2024

Fixed in 0.8.7.

Feels free to re-open if the problem stills persists

@SaltyAom SaltyAom closed this as completed Jan 1, 2024
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