Jump to content
wright

How to connect to wss:// server ?

Recommended Posts

Hey there! following the documentation of TWSocket.Addr, i tried to connect to a WebSocket "wss://ws.twelvedata.com/v1/quotes/price?apikey=api_key" using the "C:\Users\Public\...\icsv870\Samples\Delphi\SslInternet\OverbyteIcsSimpleSslCli64.dproj".

without success. i always got error like:  'Winsock Resolve Host: Cannot convert host address 'wss://ws.twelvedata.com/v1/quotes/price?apikey=api_key' - Host not found (#11001)'. Processus OverbyteIcsSimpleSslCli.exe (25544)

 

can you point me to the right direction? thx

Edited by wright

Share this post


Link to post
2 minutes ago, programmerdelphi2k said:

for your security, never publish "keys", like "APIKey" on public!

my bad thank you!

Share this post


Link to post
8 hours ago, wright said:

Winsock Resolve Host: Cannot convert host address 'wss://ws.twelvedata.com/v1/quotes/price?apikey=api_key' - Host not found (#11001)

You must pass the hostname in the TWSocket.Addr property, not a whole URL.

The hostname in your case is ws.twelvedata.com.

 

Share this post


Link to post

While ICS will connect to a Websockets server using simple TCP, ICS does not have a Websockets client, only a Websockets server,  

 

So you are on your own if any handshaking is required, sorry never looked at the WSS protocol.

 

Angus

 

Share this post


Link to post
6 hours ago, FPiette said:

You must pass the hostname in the TWSocket.Addr property, not a whole URL.

The hostname in your case is ws.twelvedata.com.

 

Hi, i forgot to said that i had already tried with only the hostname as you mentionned, but the error the same "cannot convert host address

tsslwebsocket error.png

Share this post


Link to post

the error #11001 say about "timeout" on read try not? maybe if you increase this value, if there is any communication problem on your network and the internet

(DNS lookup issue on your local network), / firewall, proxy, hosts file, etc... maybe, I dont know, for sure!

 

look this about equal error in INDY:

https://www.atozed.com/forums/thread-2250.html

Edited by programmerdelphi2k

Share this post


Link to post

I suspect your URL contains non-ASCII characters that look like ASCII, often used by phishers to hide fake URLs, but can happen for other reasons.

 

When I first tried ws.twelvedata.com ICS gave the error 'Cannot convert host address 'ws.xn--twelvedata-lb99c.com' - Host not found ' (as your screen short) which means the host name contains illegal characters and has been translated into ASCII, note the xn- part which is the giveaway.

 

When I retyped it as ws.twelvedata.com I can connect okay on port 80. 

 

Angus

 

Share this post


Link to post

You can check a host name resolution to IP address using Windows command line nslookup.

I did: ws.twelvedata.com  is has 4 IP addresses. But ws.xn--twelvedata-lb99c.com is not a valid hostname. That's your problem and NOT an ICS issue!

First thing first : check the hostname you use...

 

Share this post


Link to post
1 hour ago, FPiette said:

You can check a host name resolution to IP address using Windows command line nslookup.

I did: ws.twelvedata.com  is has 4 IP addresses. But ws.xn--twelvedata-lb99c.com is not a valid hostname. That's your problem and NOT an ICS issue!

First thing first : check the hostname you use...

 

As @Angus Robertson reported; 

 

1 hour ago, Angus Robertson said:

When I first tried ws.twelvedata.com ICS gave the error 'Cannot convert host address 'ws.xn--twelvedata-lb99c.com' - Host not found ' (as your screen short) which means the host name contains illegal characters and has been translated into ASCII, note the xn- part

so i followed what you suggested. i got no error know but no connection or it seems attempting to connect. (Port 80 even with 443) 

Edited by wright

Share this post


Link to post

If connection cannot be established, you get an error message, possibly after a long timeout.

You probably have to enable SSL/TLS in your ICS application. At least if using port 443.

 

 

 

Share this post


Link to post
1 hour ago, FPiette said:

If connection cannot be established, you get an error message, possibly after a long timeout.

You probably have to enable SSL/TLS in your ICS application. At least if using port 443.

Of course. i enabled ssl, socket familly: sfAny, 

tsslwebsocket not 1.png

Share this post


Link to post

Seems to work! i change proto to UDP. but i think it's not right way to solve it. i dig.

Share this post


Link to post
51 minutes ago, wright said:

Seems to work! i change proto to UDP. but i think it's not right way to solve it. i dig. 

Glad it works.

I have no idea which protocol wss:// use.

Maybe you should read the documentation related to wss?

Share this post


Link to post
10 hours ago, wright said:

exactly what i did. via 2 sources:

According to the sources, WSS works like HTTPS. This means you'd better inherit from THttpCli and override a few things (For example URL parsing to allow wss:// prefix).

But before doing that, start by understanding how THttpCli works using OverbyteIcsHttpsTst sample program. Verify it works for you to access a standard HTTPS server so that you are sure you correctly deployed OpenSSL which is used by ICS for all "secure" version of protocols.

 

WSS require a few specific HTTP header and THttpCli has provision for that. Probably the only modification is make THttpCli accept wss:// prefix instead of https://.

 

Also you should use WireShark to see all network communication. And a working WSS client (No need to have source) that you'll use preferably with your target website. Using WireShark, you can see the exact exchange between the client and server. You use that to compare with what you wrote with Delphi and understand where is your errors.

Share this post


Link to post

Looking into the strange host name ws.twelvedata .com posted here, in UTF-8 it is \x77\x73\x2E\x74\x77\x65\x6C\x76\x65\x64\x61\x74\x61\xEF\xBB\xBF\x2E\x63\x6F\x6D which includes a special symbol before the second dot, in UTF-8 xEF\xBB\xBF\ or #65279, which is the non-printing reserved Unicode symbol range. 

 

So you can not see it, but it copies and converts into an international domain name (like Chinese).  Potentially a risk for phishing, but no idea how it got into the original wss URL.

 

Angus

 

Share this post


Link to post

really weird. In the meantime i tried with trial version of "IPWorks ssl" all is fine, works very well. I Think i have to check inside ICS and do a proper client as you said in the upper comments!

That's the tricky part!

Share this post


Link to post

ICS will shortly have a new websocket (WSS) client component. 

 

One of our long term users has kindly contributed code extracted from a working application and a new test application which works, it will take me a few days to check throughj the source and test it thoroughly.  I will then also look at our existing websocket server which is very old code, and try to bring that up to date with SSL/TLS. 

 

Angus

 

  • Like 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×