Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sending a lot of requests to the webSocket server in a short time. Can I be sure that webSocket process the requests and respones in this order: reqA, reqB, reqC then the server responses to these requests in the same order resA, resB, resC ?


What I have tried:

I am sending a lot of requests to the webSocket server in a short time. Can I be sure that webSocket process the requests and respones in this order: reqA, reqB, reqC then the server responses to these requests in the same order resA, resB, resC ?
Posted
Updated 17-Apr-20 1:02am
Comments
[no name] 16-Apr-20 15:49pm    
no
Member 13702159 16-Apr-20 16:14pm    
0x01AA - could you please elaborate on that ?
[no name] 16-Apr-20 16:28pm    
a.) The basic protocol is TCPIP so the answers from the requests can be take completely different routes in the network. So, even the server does respond in the same order (like the request) you can not assume that answer will arrive in the same order at client side.
b.) You don't know how the server handles the requests, especally in situations where requests are distibuted to other servers (load balancing)
Member 13702159 16-Apr-20 17:05pm    
What do you think about this?
https://stackoverflow.com/questions/14287224/processing-websockets-messages-in-order-of-receiving/31894114

Someone wrote here: " WebSocket IS TCP, which means that the order of delivery is guaranteed"
[no name] 16-Apr-20 17:22pm    
TCPIP does inform you whether the information has successful send to the receiver (the request). But this has nothing to do with the response you excpect for the request you send.

Means you can send several requests successful, but you have no guarantee to 1.) receive an answer and 2.) the order the answers arrive

The only thing you can do is to serialze it:

Loop
1.) Send request
2.) Wait for answer

Or in case you are the one who program both sides (client and server), tag your requests

1 solution

TCP preserves order and has no concept of a "message". A message can be broken up into pieces, but the pieces will arrive in order. During the time that the TCP connection is kept up, the order of all "messages" will be guaranteed, but it is up to the endpoints to find the message boundaries by splitting or combining what is received on the socket. Many systems will shut down a TCP connection that remains idle, in which case the "keepalive" option must be used to prevent this.

This is not true for UDP, which can lose or reorder packets, but which will preserve message (individual packet) boundaries.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900