Roger F. Gay
Roger F. Gay

Reputation: 1961

Websockets: Meaning of named server?

A typical example explaining how to use websockets can be found here: https://developer.mozilla.org/en/WebSockets/Writing_WebSocket_client_applications.

From that page:

This simple example creates a new WebSocket, connecting to the server at http://www.example.com/socketserver. It specifies a protocol of "my-custom-protocol".

var mySocket = new WebSocket("http://www.example.com/socketserver", "my-custom-protocol");

My question has to do with "socketserver" in this example of the websocket server address. A socket server is going to be listening on a port, right? So, I can understand something like this:

var mySocket = new WebSocket("http://www.example.com:4242", "my-custom-protocol");

That would be like any old way of making a connection to a socket server, like myGuy.connect(4242);.

What type of connection is the browser using for initial access to "socketserver" above when a port number is not given? URLConnection? What?

Upvotes: 1

Views: 533

Answers (2)

David Grayson
David Grayson

Reputation: 87396

The beginning of the Websocket protocol is like HTTP. If a port is not specified in the URL, the default port of 80 is used. A connection is established using TCP/IP. The initial bytes sent by the client will include the path /socketserver in them, so that's how the host knows what the client is requesting.

Wikipedia has an example of the opening communication between a websocket client and a websocket server that you should look at: http://en.wikipedia.org/wiki/WebSocket#WebSocket_Protocol_Handshake

Upvotes: 1

Ivo Wetzel
Ivo Wetzel

Reputation: 46745

WebSockets establish a connection via an HTTP Upgrade request. So in the case above, the Web Server will re-route the Upgrade Request on /socketserver to the actual webs ocket server which then handles the connection via the WS protocol.

Upvotes: 1

Related Questions