Client side part of my application needs to process WebSocket messages in strict order. Unfortunately each message is processed quite long (about 3 seconds), so another appears before the first one has ended. After few messages the order is totally different. How to solve this problem in JavaScript.
I thought about a task queue, but I don't know how to implement it to not block GUI of my web app.
Short answer: No.
The Message event takes place usually when the server sends some data. Messages sent by the server to the client can include plain text messages, binary data, or images. Whenever data is sent, the onmessage function is fired.
The OnMessage event is raised when a client sends data to the server. Inside this event handler, the incoming message can be transmitted to the clients, or probably select only some of them.
In order to communicate using the WebSocket protocol, you need to create a WebSocket object; this will automatically attempt to open the connection to the server. The URL to which to connect; this should be the URL to which the WebSocket server will respond.
I think the other answer is wrong. WebSocket IS TCP, which means that the order of delivery is guaranteed. As @Maël Nison quoted, see RFC6455:
Message fragments MUST be delivered to the recipient in the order sent by the sender
So you can take it granted that your processing will start in order. However, if you have lots of async callbacks then a later processing may finish before an earlier is still going on. But that's simply wrong implementation (and a bit of callback hell).
Similar posts:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With