I am attemting to use WebSockets for the first time, server-side using Tomcat, and client-side using 'Java-WebSocket' (https://github.com/TooTallNate). The client application successfully connects to the Tomcat hosted webapp, sends it a serialised object (WebSocketConnectionRequest), but by the time the webapp responds a few seconds later with a serialised object of its own (WebSocketConnectionResponse) the client appears to have closed the connection.
Is there anyone here who has perhaps used the 'Java-WebSocket' library, and can explain why it is forcibly closing the connection rather than waiting to receive the ByteBuffer response?
Below is a log excerpt from the server-side webapp. It seems to be a time out thing, as once in a while the client remains connected just long enough to receive and process the server response.
posted 7 months ago
Is there anyone here who has perhaps used the 'Java-WebSocket' library?
I've not yet found an explanation or solution to this problem.
Tim Moores wrote:I'm not familiar with that particular library, but have you gotten web sockets to work at all with your server setup? If not, a simple client/server example web app (for both web sockets and server-sent events) can be found at https://coderanch.com/t/685060/java/web-app-Server-Events-SSE
Yes, the connection initially works, but quickly closes. The whole idea of using web-sockets is to keep connections open so that the server can push data to the client as and when needed, so a little annoying that it keeps closing. I'm thinking it must be a configuration oversight. I was expecting the library to work straight out of the box.
I'll take a look at the code you linked to for some clues, and change libraries if necessary.
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java