There appears to be a bug in Websocket Client....  

I am getting "java.io.IOException: An existing connection was forcibly
closed by the remote host". This appears to be when the websocket client is
closed before all the information has been sent.

Surely session.close should wait until everything has been sent?.....  

I'm not actually sure how to fix this in code... maybe having the client
send an 'end-of-data', then the server send an acknowlegement of the
end-of-data, and only then close the socket?

But....is this a workaround for a bug?

At the moment, I am using https://github.com/TooTallNate/Java-WebSocket
instead, which doesn't have this issue.  To reproduce: Create the following
2 classes,  then navigate to http://localhost:8080/  :




WebsocketClient.java

import java.io.IOException;
import java.net.URI;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.websocket.*;
import javax.websocket.RemoteEndpoint.Basic;

@WebServlet("/")
public class WebsocketClient extends HttpServlet {
        
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws ServletException, IOException {
                
                 try {
                         
                        Session session = 
ContainerProvider.getWebSocketContainer()
                                    .connectToServer(new MyEndpoint(),new
URI("ws://localhost:8080/WebsocketClientBug/ws/testing"));
                        
                        
                        Basic br = session.getBasicRemote();
                        for (int i=0; i<100; i++){
                                br.sendText("this is some random text");
                        }
                        session.close();
                        
                } catch (Exception e) {e.printStackTrace();}
        }
        
        
        @ClientEndpoint
        public static class MyEndpoint{
                @OnError
                public void error(Throwable err){
                        err.printStackTrace();
                }
        }
        
}




WebsocketServer.java

import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/ws/testing")
public class WebsocketServer {

        @OnMessage
        public void message(Session sess, String payload){
                try {
                        Thread.sleep(10);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
        
}




--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/Websocket-Client-Bug-tp4678282.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Reply via email to