Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can WebSockets and HTTP server both run on the SAME port number?

I have been using GlassFish server, where, index.html is sending the control to servlet file which is sending the control to another nextStep.html file, which is working on WebSockets. Right now, I am confused, as I am getting an error:

WebSocket connection to 'LocalHost-link' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I think this problem is related to port numbers. Can we use both WebSockets and HTTP server on the same port, if yes, then How ? If we have to use different ports, then how to perform this task in Java ?

like image 886
manpreetSingh Avatar asked Apr 07 '15 17:04

manpreetSingh


People also ask

Can I use WebSockets and HTTP?

WebSocket uses HTTP as the initial transport mechanism, but keeps the TCP connection alive after the HTTP response is received so that it can be used for sending messages between client and server.

Which port should I use for WebSocket?

1.7. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].

How do WebSockets maintain compatibility with HTTP?

WebSocket solves a few issues with HTTP: Bi-directional protocol — either client/server can send a message to the other party (In HTTP, the request is always initiated by the client and the response is processed by the server — making HTTP a uni-directional protocol)

Can WebSockets send and receive at the same time?

The key word in that definition is two-way: with WebSocket, both the client and the server can trigger communication with one another, and both can send messages, at the same time.


1 Answers

To provide this question with an answer: Yes, they can.

See also:

  • Is it possible to enable tcp, http and websocket all using the same port?
  • Running a websocket server and a http server on the same server
like image 80
unwichtich Avatar answered Oct 17 '22 14:10

unwichtich