wright 2 Posted November 27, 2022 (edited) 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 November 27, 2022 by wright Share this post Link to post
programmerdelphi2k 237 Posted November 27, 2022 (edited) for your security, never publish "keys", like "APIKey" on public! Edited November 27, 2022 by programmerdelphi2k Share this post Link to post
wright 2 Posted November 27, 2022 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
FPiette 383 Posted November 28, 2022 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
Angus Robertson 574 Posted November 28, 2022 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
wright 2 Posted November 28, 2022 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" Share this post Link to post
programmerdelphi2k 237 Posted November 28, 2022 (edited) 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 November 28, 2022 by programmerdelphi2k Share this post Link to post
Attila Kovacs 629 Posted November 28, 2022 "Host not found" to "ws.xn--twelvedata-lb99c.com" You will not have the drink, Kimi. Share this post Link to post
Angus Robertson 574 Posted November 28, 2022 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
FPiette 383 Posted November 28, 2022 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
wright 2 Posted November 28, 2022 (edited) 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 November 28, 2022 by wright Share this post Link to post
FPiette 383 Posted November 28, 2022 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
wright 2 Posted November 28, 2022 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, Share this post Link to post
wright 2 Posted November 28, 2022 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
FPiette 383 Posted November 28, 2022 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
wright 2 Posted November 28, 2022 (edited) exactly what i did. via 2 sources: 1. https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake 2. attached png but i don't know why in my case TCP proto doesn't work. im still learning delphi prog and websocket, i'll check again for a better workarround. Edited November 28, 2022 by wright Share this post Link to post
Fr0sT.Brutal 900 Posted November 29, 2022 The whole idea of websockets is to have permanent connection so it should use TCP. 1 Share this post Link to post
FPiette 383 Posted November 29, 2022 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
Angus Robertson 574 Posted November 29, 2022 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
wright 2 Posted December 2, 2022 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
Angus Robertson 574 Posted December 12, 2022 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 3 Share this post Link to post
wright 2 Posted December 27, 2022 Hello guys! @Angus Robertson, any progress? Share this post Link to post
Angus Robertson 574 Posted December 27, 2022 The new ICS websocket client is done, just updating the REST sample with a websocket tab, day or two. Angus 2 Share this post Link to post