Ky P
Ky P

Reputation: 31

Why do websockets and HTTP conflict?

I am trying to use the same port on the same host.

Websocket URL
ws://aaa.bbb.cc.ddd:eeee/ws


HTTP URL
http://aaa.bbb.cc.ddd:eeee/docs

But when I open the "http://aaa.bbb.cc.ddd:eeee/docs" page, I get this error message.

Failed to open a WebSocket connection: invalid Connection header: keep-alive.
You cannot access a WebSocket server directly with a browser. You need a WebSocket client.

Http does not work. But, websocket is connected normally.

How can I solve this problem?

Upvotes: 1

Views: 1397

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595349

The WebSocket protocol is not the HTTP protocol.

Although the WebSocket protocol does initiate a new connection using an HTTP request, it quickly upgrades the connection to full WebSocket (which requires a Connection: upgrade header in the initial request, not Connection: keep-alive).

You can't use a vanilla web browser to directly communicate with a WebSocket URL, as such a browser doesn't know how to finish the upgrade, let alone process any WebSocket packets. So, you must use a valid WebSocket client (such as the WebSocket API that modern browsers expose to client-side scripting).

Upvotes: 2

Related Questions