Skip to main content
1-Visitor
December 18, 2015
Solved

Error connecting Java Edge SDK sample program to Thingworx server:

  • December 18, 2015
  • 1 reply
  • 7084 views

I am getting the error when I try to run the sample java program bundled in ThingWorx Java SDK.

11:25:46.456 [Client-EndpointMonitor-1] ERROR c.t.c.c.c.n.NettyClientConnectionFactory - Exception occurred while connecting to server

java.util.concurrent.TimeoutException: timeout waiting for websocket handshake to complete

  at com.thingworx.communications.client.connection.netty.NettyClientConnectionFactory$HandshakeCompletionNotifier.await(NettyClientConnectionFactory.java:563) ~[thingworx-communications-client-6.0.0.189.jar:na]

  at com.thingworx.communications.client.connection.netty.NettyClientConnectionFactory.createConnection(NettyClientConnectionFactory.java:309) ~[thingworx-communications-client-6.0.0.189.jar:na]

  at com.thingworx.communications.client.endpoints.ClientCommunicationEndpoint.refillConnections(ClientCommunicationEndpoint.java:225) [thingworx-communications-client-6.0.0.189.jar:na]

  at com.thingworx.communications.common.endpoints.monitor.ConnectivityMonitorTask.dutyCycleOn(ConnectivityMonitorTask.java:150) [thingworx-communications-client-6.0.0.189.jar:na]

  at com.thingworx.communications.common.endpoints.monitor.ConnectivityMonitorTask.run(ConnectivityMonitorTask.java:264) [thingworx-communications-client-6.0.0.189.jar:na]

  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_66]

  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_66]

  at java.lang.Thread.run(Unknown Source) [na:1.8.0_66]

11:25:46.456 [Client-EndpointMonitor-1] INFO  c.t.c.c.c.n.NettyClientConnectionFactory - forcing underlying tcp channel closed [is open: false, is active: false]

11:25:46.457 [Client-EndpointMonitor-1] ERROR c.t.c.c.e.ClientCommunicationEndpoint - Refilling connections on [endpoint 0, uri: wss://localhost:80/Thingworx/WS] failed : timeout waiting for websocket handshake to complete

11:25:46.458 [Client-EndpointMonitor-1] ERROR c.t.c.c.e.ClientCommunicationEndpoint - Exception refilling connections was:

Connection setup information in the java client is as follows:

  config.setUri("ws://localhost:80/Thingworx/WS");

I have tried importing a certificate in tomcat (tomcat listens on port 8443 after that) and changed the connection information as follows:

  config.setUri("wss://localhost:8443/Thingworx/WS");

But that also gives me similar error.

Can some one please guide me how to fix this error?

Best answer by billrei

This message usually occurs because you have connected to a server that is unable to negotiate a websockets upgrade to your connection. Normally your connection is established on whatever port you specify. In this case you specified port 80 on your local machine. A connection was established but when the SDK asked for this connection to be upgraded from HTTP to websockets, the server did not respond. This can happen if you are talking to a web proxy between you and the server that does not understand websockets but in your case I would like you to confirm that your ThingWorx server is on port 80 and not port port 8080 which is the default. You may already have a server on port 80 that does not support websockets.

1 reply

billrei12-AmethystAnswer
12-Amethyst
December 18, 2015

This message usually occurs because you have connected to a server that is unable to negotiate a websockets upgrade to your connection. Normally your connection is established on whatever port you specify. In this case you specified port 80 on your local machine. A connection was established but when the SDK asked for this connection to be upgraded from HTTP to websockets, the server did not respond. This can happen if you are talking to a web proxy between you and the server that does not understand websockets but in your case I would like you to confirm that your ThingWorx server is on port 80 and not port port 8080 which is the default. You may already have a server on port 80 that does not support websockets.

nkumar-211-VisitorAuthor
1-Visitor
December 21, 2015

Thanks Bill for the early reply.

I ran the SDK client again in an open Internet environment (without a proxy server between the client and the Thingworx server) and it worked flawlessly.

1-Visitor
June 27, 2016

Hi Bill,

We are also trying to connect java SDK to secured(https) thingworx server and it's working with open network.

Actually we need to connect java SDK to  thingworx server hosted on machine which is available in a private network.

so please provide the steps if there are settings need to be done?