Reputation: 2929
I am checking out the behaviors of Websocket. Is Websocket message oriented unlike TCP stream?
For example, when I send data ABC, DEF, GHI, then is it guaranteed to receive data ABC, DEF, GHI? In TCP stream, it is not guranteed: we may receive AB, DEFG, HI.
Upvotes: 2
Views: 483
Reputation: 595392
Yes, it is message-oriented (well, actually frame-oriented).
Per RFC 6455:
After a successful handshake, clients and servers transfer data back and forth in conceptual units referred to in this specification as "messages". On the wire, a message is composed of one or more frames. The WebSocket message does not necessarily correspond to a particular network layer framing, as a fragmented message may be coalesced or split by an intermediary.
...
The WebSocket Protocol is designed on the principle that there should be minimal framing (the only framing that exists is to make the protocol frame-based instead of stream-based and to support a distinction between Unicode text and binary frames). It is expected that metadata would be layered on top of WebSocket by the application layer, in the same way that metadata is layered on top of TCP by the application layer (e.g., HTTP).
Conceptually, WebSocket is really just a layer on top of TCP that does the following:
adds a web origin-based security model for browsers
adds an addressing and protocol naming mechanism to support multiple services on one port and multiple host names on one IP address
layers a framing mechanism on top of TCP to get back to the IP packet mechanism that TCP is built on, but without length limits
includes an additional closing handshake in-band that is designed to work in the presence of proxies and other intermediaries
Upvotes: 5