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 ?
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.
1.7. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].
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)
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.
To provide this question with an answer: Yes, they can.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With