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

Failure to Connect SteamSensor to an External Server

aherger
1-Newbie

Failure to Connect SteamSensor to an External Server

Hello,

I am currently following the SteamSensor example for Thingworx and have hit a problem.  I was successfully able to connect to a local instance of Thingworx as well as one located on my network.  However, when I try to connect to an external server, the connection seems to time out.

I am currently working with the C SDK, and am unable to tell if this is a problem with the server or the agent.  Below I have posted the output from the SteamSensor program.  I should note that the version of the Thingworx instance is 6.0.2, and that I am trying to connect on port 443.  Any ideas on the cause of this issue would be appreciated.

Thank You.

[FORCE] 2016-06-07 08:18:15,354: Starting up

[DEBUG] 2016-06-07 08:18:15,355: twWs_Create: Initializing Websocket Client for

“<PTC Hosted Thingworx instance>”

[DEBUG] 2016-06-07 08:18:15,355: twTlsClient_Create: Initializing TLS Client

[DEBUG] 2016-06-07 08:18:15,456: twApi_Initialize: Websocket Established after 0

tries

[DEBUG] 2016-06-07 08:18:15,457: subscribedPropsMgr_Initialize: Initializing sub

scribed properties manager

[DEBUG] 2016-06-07 08:18:22,129: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:18:22,135: twTlsClient_Connect: Connecting to server

[ERROR] 2016-06-07 08:18:32,137: twWs_Connect: Error trying to connect

[DEBUG] 2016-06-07 08:18:32,137: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:18:32,156: twTlsClient_Connect: Connecting to server

[DEBUG] 2016-06-07 08:18:37,157: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:18:37,164: twTlsClient_Connect: Connecting to server

[ERROR] 2016-06-07 08:18:47,173: twWs_Connect: Error trying to connect

[DEBUG] 2016-06-07 08:18:47,173: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:18:47,192: twTlsClient_Connect: Connecting to server

[DEBUG] 2016-06-07 08:18:52,198: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:18:52,209: twTlsClient_Connect: Connecting to server

[ERROR] 2016-06-07 08:19:02,212: twWs_Connect: Error trying to connect

[DEBUG] 2016-06-07 08:19:02,212: twTlsClient_Reconnect: Re-establishing SSL cont

ext

[DEBUG] 2016-06-07 08:19:02,222: twTlsClient_Connect: Connecting to server

[ERROR] 2016-06-07 08:19:07,224: twApi_Connect: Max number of connect retries: 3

, has been reached

[ERROR] 2016-06-07 08:19:07,224: main: Server connection failed after 3 attempts

.  Error Code: 201

13 REPLIES 13
Aanjan
9-Granite
(To:aherger)

Andrew, can you ping the server? Are there any firewalls on your side or the external server side?

aherger
1-Newbie
(To:Aanjan)

I can successfully ping the server.  Our firewall doesn't appear to be blocking the connection, however I am unsure how to test the PTC hosted server's firewall.  Is it possible I have something disabled in the example that needs to be enabled for connecting to external servers?

Aanjan
9-Granite
(To:aherger)

Can you post your connection Uri?

aherger
1-Newbie
(To:Aanjan)

Do you need the full string?  Or will this be enough?  Sorry for the delayed response.

**********************************************.com:443//Thingworx/WS

Aanjan
9-Granite
(To:aherger)

I wanted to check if it was formatted correctly, as in wss://server:443/Thingworx/WS

aherger
1-Newbie
(To:Aanjan)

Sorry about that.  The beginning of the URI I posted did not have a "wss://" at the beginning.  In other words, it started with the server's name, giving it the format off, "server:443//Thingworx/WS". Note, I pulled my URI from the debug output shown above in the spot where “<PTC Hosted Thingworx instance>” is now.  When I define host in main.c do I need to put "wss://server" instead of just the server's name?

Aanjan
9-Granite
(To:aherger)

Yes, you would need to have wss in the beginning, as this makes it a websocket secure connection. For a non secure (or non ssl) port, the Uri usually reads as ws://server:80/Thingworx/WS

aherger
1-Newbie
(To:Aanjan)

Alright, I added on "wss://" so now...

host = wss://ServerName

port = 443

TW_URI = /Thingworx/WS

TW_APP_KEY = A key created on the external server

Now I'm getting a new error that says, "twApi_Initialize: Error creating websocket structure, retrying".  This will fail three times and then the program will exit saying "Error initializing the API".  Any ideas on how to correct this issue? 

Aanjan
9-Granite
(To:aherger)

Andrew, sorry I didn't realize the flags were broken up. Have you looked at the Edge Help Center? Click here for information regarding configuring the API Singleton.

aherger
1-Newbie
(To:Aanjan)

Thank you for the link.  I went through the documentation today, but I don't quite see the problem.  Just to double check everything, I downloaded a fresh copy of the C SDK and went through the tutorial outlined here. I also checked that there was no proxy server involved in the connection.  Unfortunately, I am still getting the same error.


[ERROR] 2016-06-10 15:37:44,462: twWs_Create: Error creating BSD socket to be used for the websocket

[ERROR] 2016-06-10 15:37:44,462: twApi_Initialize: Error creating websocket structure, retrying

Is there anything that I have to do on the Thingworx instance or Axeda Server to allow the connection? or have I possibly missed steps not included in the tutorial?

Thank you for your help so far.

Aanjan
9-Granite
(To:aherger)

That's interesting, I've come across BSD socket errors if there is a proxy (mainly, reverse proxy) involved, or if there is a firewall or something similar that does not support websockets. Is there a chance you can connect to a different server that is out of your current network? If you have it connected to a local instance, then you're pretty much set; other than changing the basic host/port and appKey, you shouldn't have to change anything else.

aherger
1-Newbie
(To:Aanjan)

I haven't tried connecting to another Thingworx instance outside of my network yet.  I'll try to find a server I can use.   Is there a Thingworx instance hosted by PTC that can be connected to for testing purposes? Perhaps one made for the PTC University Thingworx tutorials?

Aanjan
9-Granite
(To:aherger)

I don't think we have one setup for testing/ connection purposes. If you don''t have access to our eSupport portal and the downloads, you can sign up for our Developer trial edition at the Developer Zone.

Top Tags