3 Replies Latest reply: May 16, 2012 4:19 AM by Jean-Frederic Clere RSS

    Error with WebSocket connection

    Wesley Hales Master

      What up folks! I'm Getting multiple errors when connecting from 2 separate tabs within the same (chrome) web browser.

       

      14:04:52,892 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[com.onslyde.websockets.PresentationHandler]] (http-/172.24.110.175:8080-1) Servlet.service() for servlet com.onslyde.websockets.PresentationHandler threw exception: org.apache.tomcat.jni.Error: Socket operation on non-socket
                at org.apache.tomcat.jni.Socket.sendbb(Native Method) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:854) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.InternalAprOutputBuffer.flush(InternalAprOutputBuffer.java:316) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.Http11AprProcessor.action(Http11AprProcessor.java:1062) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.Response.action(Response.java:190) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:347) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:316) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:98) [jbossweb-7.0.16.Final.jar:]
                at org.jboss.websockets.oio.internal.protocol.ietf13.Hybi13Socket._writeTextFrame(Hybi13Socket.java:181) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.jboss.websockets.oio.internal.protocol.ietf13.Hybi13Socket.writeFrame(Hybi13Socket.java:255) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.jboss.as.websockets.servlet.WebSocketDelegate.writeFrame(WebSocketDelegate.java:41) [jboss-as-websockets-0.2.Alpha1.jar:]
                at com.onslyde.websockets.PresentationHandler.onReceivedFrame(PresentationHandler.java:113) [classes:]
                at org.jboss.as.websockets.servlet.WebSocketServlet.event(WebSocketServlet.java:166) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:494) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:399) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardWrapperValve.event(StandardWrapperValve.java:464) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardContextValve.event(StandardContextValve.java:183) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.valves.ValveBase.event(ValveBase.java:193) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.valves.ValveBase.event(ValveBase.java:193) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:259) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.valves.ValveBase.event(ValveBase.java:193) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:128) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:265) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.Http11AprProcessor.event(Http11AprProcessor.java:780) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.event(Http11AprProtocol.java:587) [jbossweb-7.0.16.Final.jar:]
                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2033) [jbossweb-7.0.16.Final.jar:]
                at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_31]
      
      
      14:04:57,681 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[com.onslyde.websockets.PresentationHandler]] (http-/172.24.110.175:8080-1) Servlet.service() for servlet com.onslyde.websockets.PresentationHandler threw exception: java.lang.IllegalStateException
                at org.apache.catalina.connector.ResponseFacade.startUpgrade(ResponseFacade.java:461) [jbossweb-7.0.16.Final.jar:]
                at org.jboss.as.websockets.servlet.WebSocketServlet$2.startUpgrade(WebSocketServlet.java:137) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.jboss.websockets.oio.WebSocketConnectionManager.establish(WebSocketConnectionManager.java:39) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.jboss.as.websockets.servlet.WebSocketServlet.event(WebSocketServlet.java:144) [jboss-as-websockets-0.2.Alpha1.jar:]
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:494) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:399) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:273) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final.jar:]
                at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.2.Final-SNAPSHOT.jar:7.1.2.Final-SNAPSHOT]
                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final-SNAPSHOT.jar:7.1.2.Final-SNAPSHOT]
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final.jar:]
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.16.Final.jar:]
                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:634) [jbossweb-7.0.16.Final.jar:]
                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.16.Final.jar:]
                at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_31]
      
      

       

      Here's some hacked together code to reproduce the error:

       

      private Set<WebSocket> websockets = new HashSet<WebSocket>();
      
      @Override
          protected void onSocketOpened(WebSocket socket) throws IOException {
              System.out.println("Websocket opened :)");
              getWebsockets().add(socket);
          }
      
      
          @Override
          protected void onSocketClosed(WebSocket socket) throws IOException {
              System.out.println("Websocket closed :(");
              getWebsockets().remove(socket);
          }
      
      
          @Override
          protected void onReceivedFrame(WebSocket socket) throws IOException {
              final Frame frame = socket.readFrame();
              if (frame instanceof TextFrame) {
                  final String data = ((TextFrame) frame).getText();
      
                   String  clientString = ("foo");
                  
                      for (WebSocket asocket : getWebsockets()) {
                          System.out.println("!!!!!!!!!!!!!!!!!!" + asocket.getSocketID());
                          try{
                              System.out.println("!!!!!!!!!!!!!!!!!!asocket: " + asocket);
                              asocket.writeFrame(TextFrame.from(clientString));
                              Class cls = asocket.getClass();
                              System.out.println("The type of the object is: " + cls.getName());
                          }catch (Exception e){
                              System.out.println("!!!!!!!!!!!!!!!!!!you get not a socket error: " + e);
                              //still happens with below
                              getWebsockets().remove(asocket);
                          }
                      }
                
              }
          }
      
           private Set<WebSocket> getWebsockets() {
              return websockets;
          }