14 Replies Latest reply on Mar 16, 2017 11:13 AM by ttyler RSS
    asiqueira-2 Explorer

    Cant connect to thingWorx servers

    Hi,

    I'm starting to develop with JAVA SDK, followed the samples examples but i cant stablish a connection with ThingWorx Server or localhost

     

     

    System.out.println("Example:");
    System.out.println("ws://localhost:80/Thingworx/WS xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 1000 1 10");
    

     

    I tested this URI but console shows this:

     [Client-EndpointMonitor-1] INFO  c.t.c.c.c.n.NettyClientConnectionFactory - forcing underlying tcp channel closed [is open: false, is active: false]
     [Client-EndpointMonitor-1] ERROR c.t.c.c.e.ClientCommunicationEndpoint - Refilling connections on [endpoint 0, uri: ws://locahost:80/Thingworx/WS] failed : timeout waiting for websocket handshake to complete
     [Client-EndpointMonitor-1] INFO  c.t.c.c.e.m.CommunicationEndpointMonitorTask - Endpoint reconnection was unsuccessful [name: SteamSensorGateway, id: 0]
    

     

     

     

    I may missing something,maybe some obvious things,

     

    if anyone could help.

      • Re: Cant connect to thingWorx servers
        aanjan Heavyweight Champ

        Can you try connecting over a secure connection? If you platform is not setup for SSL, here is an article link on how to setup SSL on Tomcat with a self-signed certificate.

        • Re: Cant connect to thingWorx servers
          ianban Creator

          The Java SDK connection is usually pretty easy to get working, especially with a non-secure environment.

           

          So, some bvious questions but worth checking:

           

          1) ThingWorx and Tomcat are set to use port 80? Tomcat install defaults to 8080.

          2) ThingWorx and your Steam Sensor jar file are on the same machine

           

          I don't think you're getting as far as authenticating so these are just to make sure....

           

          3) You've created an AppKey and are replacing all of the xxx-xxxxxx bits with that.

          4) If you're using windows and have copied and pasted the appKey, go back through it and replace the dashes, Windows occasionally corrupts these by replacing them with other characters that look like dashes.

           

          Regards

           

          Ian

            • Re: Cant connect to thingWorx servers
              asiqueira-2 Explorer

              Thank you guys, but unfortunately it didnt work

               

              I changed tomcat's port to 80 but i dont think if i'm getting this, when you say to set also thingworx port to 80 you mean the URI right ?

               

              Another thing that happens is when i run the SteamSensorClient,the initial status in console show that WebSocket channel is connected:

               

              09:19:27.681 [NettyClient-NIO-1] DEBUG c.t.c.c.c.n.ThingworxClientConnectionHandler - WebSocket Channel is connected [is open: true]
              09:19:27.683 [NettyClient-NIO-1] DEBUG i.n.h.c.h.w.WebSocketClientHandshaker13 - WebSocket version 13 client handshake key: xxxxxxxxxxxx==, expected response: xxxxxxxxxx=
              


              But after a couple seconds it says that the connection was unsuccessfully,the error you alerady know.

            • Re: Cant connect to thingWorx servers
              billrei Creator

              Your logs indicate that you are connecting to the ThingWorx server. You are just failing to establish a WebSocket upgrade on that existing connection. The Java SDK starts by establishing an HTTP connection just like your browser. Once that is established, the Java SDK asks your server if it would be ok to change the protocol from HTTP to WebSockets. Your server is failing to respond to the WebSocket upgrade request. This may be because of an proxy server sitting between your device and the server that does not pass on your WebSocket upgrade request. You may want to consult with your IT department to see if this is the case. They may be able to permit your request to pass through to the ThingWorx server where it is currently being blocked.