Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a resource in a WebSocket URL?

Tags:

websocket

Looking at the W3 spec on WebSockets, I see

var socket = new WebSocket('ws://game.example.com:12010/updates');
socket.onopen = function () {
  setInterval(function() {
    if (socket.bufferedAmount == 0)
      socket.send(getUpdateData());
  }, 50);
};

I understand that the socket services lives on port 12010 at game.example.com, but what is the purpose of the '/updates' resource in the URL? If the service lives at some port, what good will a resource do?

like image 217
Chad Johnson Avatar asked Apr 24 '11 22:04

Chad Johnson


People also ask

What is WebSocket in Web IDL?

WebSocket. WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C . WebSocket is a different protocol from HTTP.

What is web socket and how is it different from http?

What is web socket and how it is different from the HTTP? - GeeksforGeeks What is web socket and how it is different from the HTTP? HTTP and WebSocket both are communication protocols used in client-server communication. HTTP protocol: HTTP is unidirectional where the client sends the request and the server sends the response.

Why do we use WebSockets?

For handshaking, the HTTP protocol sends and receives some extra bytes just to confirm whether a port is free in both the machines and fetches the details of the port. These extra bytes are an overhead when the frequent exchange of information is required. Hence, WebSocket. When to use WebSocket and When not to?

What is a URL?

Definition from SearchNetworking What is a URL? A URL (Uniform Resource Locator) is a unique identifier used to locate a resource on the Internet. It is also referred to as a web address. URLs consist of multiple parts -- including a protocol and domain name -- that tell a web browser how and where to retrieve a resource.


1 Answers

You can expose different logical WebSockets on the same port, using different URI's.

Lets take chat as an example. You could use the URI to determine the particular channel or chat room you want to join.

var socket = new WebSocket('ws://chat.example.com/games');
var socket = new WebSocket('ws://chat.example.com/movies');
var socket = new WebSocket('ws://chat.example.com/websockets');

You can also use query strings. Imagine a stock ticker:

var socket = new WebSocket('ws://www.example.com/ticker?code=MSFT');
var socket = new WebSocket('ws://www.example.com/ticker?code=GOOG');
like image 77
Paul Batum Avatar answered Nov 12 '22 14:11

Paul Batum