20

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 ?

manpreetSingh
  • 654
  • 4
  • 8
  • 20
  • 3
    Yes it can run on the same port, in fact it must run on the same port; the raison d'etre of websocket handshake is so that the websocket can run on the same connection without confusing intermediaries that doesn't understand websocket. – Lie Ryan Apr 07 '15 at 17:56
  • 1
    @LieRyan ok. While running the websockets on the same port, I am getting an error: `Error during WebSocket handshake: Unexpected response code: 404` , can you guide me how to resolve this ? – manpreetSingh Apr 07 '15 at 17:59
  • 1
    Your web server must understand websocket and must expect a websocket connection on the URL you're connecting to. You are getting 404 Not Found because the server is not expecting a websocket request on that URL. – Lie Ryan Apr 07 '15 at 18:04
  • 3
    Or the websocket uri is incorrect ... – jHilscher Apr 07 '15 at 18:05
  • @manpreetSingh how did you do that? i am facing the same issue. – Swaprks Sep 13 '17 at 18:08
  • @Swaprks: Hi, actually I don't remember exactly how I solved this one, but here is the link to the Git repo, I hope it helps. https://github.com/manpreetSinghkhalsa/CollabEdit2.0 – manpreetSingh Sep 14 '17 at 11:12

1 Answers1

14

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

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66