TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.47k stars 2.57k forks source link

I have a client that is supposed to send multiple types of messages to a server, and based on the message the server receives it sends to the client a specific json. On the onMessage method the client receive the message and I would like to parse the message based on the type of message the client sent to the server. The client is sending messages to the server in serial, and the onMessage need to process the messages in serial as well. Is there a way to let the onMessage method to know what kind of message the client sent to the server so it's easy to process the messages without parsing the message itself? #1361

Closed gancarani closed 10 months ago

gancarani commented 1 year ago

**

Describe what you would like to know or do** A clear and concise description of what the problem is.

Describe the solution you'd considered A clear and concise description of any solutions you've considered.

Additional context Add any other context or links about the question here.

PhilipRoman commented 1 year ago

WebSocket can only distinguish 2 message types: binary and text. Everything else needs to be handled in your code. You can, for example, wrap it in a JSON object, prefix with some identifier, etc.

This library only implements the WebSocket protocol which doesn't have such functionality.

gancarani commented 1 year ago

Thanks, an in your opinion what would be the best way to handle different messages? Is there a pattern to use that is better than the others?

PhilipRoman commented 10 months ago

Closing as this is off topic I recommend asking this question in a general programming forum, not here.