开发者

websockets: do they shared the connection?

If I have requests for multiple resources, do they share the connection? So if I have these requests:

  • ws://someserver.com/path/somedata1
  • ws://someserver.com/path/somedata2
  • ws://somsserver.com/anotherpath/someotherdata

From what I've read so far, I would have to create 3 websockets to get the data from these urls. All the examples I've seen open a connection, get the data and close the connection. But if I've created 3 websockets, do they (under the covers) share a single connection to someserver.com? or are they 3开发者_StackOverflow separate connections? meaning 3 sockets each side of the link, etc.


There is ongoing discussion in the working group about getting automatic muxing of websockets connections to the same server but there is no existing implementation with support for this so if you open three websockets connections you will get three TCP socket connections under the hood.

However, if you control both the client and server then there probably isn't a reason for your application to open three separate connections to separate URLs. Just open a single connection and then in your application level protocol have a way of specifying the resource you want. Also, one of the big advantages of WebSockets over HTTP connections is that the connection stays open and is full duplex bidirectional and message based. Often current WebSocket applications choose to send JSON messages back and forth and but once you have the WebSocket connection established you can send whatever you want back and forth (currently limited to what you can encode to UTF-8 strings but raw binary will be supported in the future).

The URL that is part of the WebSocket connection is really just another part of the WebSocket handshake. If the server configuration is a webserver that is upgrading connections to WebSockets server then the URL could be used to select which WebSockets server to pass the connection to. However, if you have a raw WebSockets server answering the connections than the URL is just another piece of data in the handshake and the server can decide to do whatever it wants with the URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜