cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Cant connect to thingWorx servers

asiqueira-2
1-Newbie

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.

14 REPLIES 14

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.

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

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.

if your URL for composer is http://someserver.somewhere.net/Thingworx then you're using port 80. Your composer URL is http://someserver.somewhere.net:8080/Thingworx then you're using port 8080.

Can you set the ThingWorx communication log to trace and re-try the connection, that way you'll get the Server's view of what is happening. You can also set up logging in the Steam Sensor code so it reports what's going on. If you want to capture what's being output in the terminal window when you run the jar file (if you're using an executable Jar, then java -jar SteamSensor.jar >> Logfile.txt works, note that the file is only written once you kill the process.)

Thingworx's URL ends just with ".com", it also mean port 80? Sorry if its a obvious thing, but i thing the error is about thingworx port

mhollenbach
5-Regular Member
(To:asiqueira-2)

Did you try appending :80 after .com?

I tried now,and it disappears and reload the page normally,maybe it mean that the port is 80,what you think?

mhollenbach
5-Regular Member
(To:asiqueira-2)

If it is disappearing and the page loads then you are accessing port 80. Regardless, you will need to define this in the config.setUri() line within the SteamSensorClient. Ports have to be explicitly defined within the URI string. ex: config.setUri("ws://localhost:80/Thingworx/WS");

Yep, that sounds right, it is 80. Can you post the entire Uri you are using? Also, config.ignoreSSLErrors is set to true, correct? Since you are testing this locally right now, this connection would be fine, but please do look into setting up SSL connectivity too.

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

My Uri .




  1. config.ignoreSSLErrors(true);

And SSLE flag .



Still not working.When i run the client the first relevant thing appears like this:


08:54:21.400 [NettyClient-NIO-1] DEBUG c.t.c.c.c.n.ThingworxClientConnectionHandler - WebSocket Channel is connected [is open: true]

08:54:21.402 [NettyClient-NIO-1] DEBUG i.n.h.c.h.w.WebSocketClientHandshaker13 - WebSocket version 13 client handshake key: waDt491XCPgxa7m4bblRiA==, expected response: GHCGSYsVZmdiRojxDyzV/WwLEkw=

After a few seconds the error show his face:

08:55:48.857 [Client-EndpointMonitor-1] INFO  c.t.c.c.c.n.NettyClientConnectionFactory - forcing underlying tcp channel closed [is open: false, is active: false]

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

08:55:48.857 [Client-EndpointMonitor-1] INFO  c.t.c.c.e.m.CommunicationEndpointMonitorTask - Endpoint reconnection was unsuccessful [name: SteamSensorGateway, id: 0]

I dont know if it's the Network,what you think?

Hi,

You can also check this video tutorial on how to use the SteamSensor from the  Java Edge SDK with the Eclipse IDE.

Tutorial: Send Data to the ThingWorx Server from Java Edge SDK Programs

billrei
5-Regular Member
(To:asiqueira-2)

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.

Make sense Bill, i'll check it!

Regards

Hi Aldo, did you get a resolution from this by any chance? Same problem here

Cheers, Tim

Top Tags