Jump to content

plastkort

Members
  • Content Count

    41
  • Joined

  • Last visited

Posts posted by plastkort


  1. 2 hours ago, Angus Robertson said:

    I assume you are talking about a websocket client component, there is such a new component in ICS V8.71 not released yet but can be downloaded from the overnight zip or SVN. 

     

    The new client is in OverbyteIcsWebSocketCli.pas with a sample in OverbyteIcsHttpRestTst.dpr (because it descends from the HTTP REST component). 

     

    It's been tested against a couple of public websocket servers, and both of the ICS server implementations, one is new and built into the multi web server sample.  It's also running on one of my public web sites, which the sample tests against.

     

    Angus

    i'd sure give this a test, but I am not sure where I can find this download link?


  2. Earlier I made my own version for a specific websocket connection, however now it seems that the service I connect to has changed something and I have no clue what. I can still connect to them using openSSH directly, however with my modified TSSLWsocket I can no longer connect, It just immediately disconnects with the error code 10053 (wsaeconnaborted) i tried to reboot routers and modems but still nothing. application I made was connected on another computer which eventually died the next time I tried to start it.

     

    so I suspect that i might need some other kind of websocket component, but hopefully I can still use TSSLWsocket, anyone here have something I can use ?


  3. i think the only way is to create one yourself, but for the community i think it would be good to have more of these new socket services...

     

    I am currently using a webhook from tradingview for alert notifications, but i guess it's not really the same webhook, more or less its just sending a post to my own server.

     

     


  4. hmm.. it seems this appserver will overcomplicate my simple project.. I did however notice something in your sample files called:

    OverbyteIcsSrv5

     

    i use     "FNewSocket := _TWSocket(sender).Accept;"

     

    but i did not apply the FnewSocket := TWSocket(sender).dup

     

    is this a very important part i was missing ?

     

    also i have added :

    ShutDown(2); 
    Close;       

     

    and will see if this allows my server to live longer, note, it's only the listening socket that died earlier, and not the rest of my program. however im not sure if it just stopped listen or something else messed it up

     

     


  5. 1 hour ago, FPiette said:

    HTTP protocol is more complex than you think...

     

    There is also THttpAppSrv component and his demo application OverbyteIcsWebAppServer.

    THttpAppSrv is more oriented to answer with "computed" responses.

     

     

    That one might do the trick, but i hope it can be simplified. I just require it to receive a POST message, and just reply a simple instruction page on the default.

     

    but I would also appreciate if you have any answer to why my listening socket just stops listening after a while, im concerned that this happens on other projects i might be planning to do in the future. are there any sample codes around I can take a look at so i know that i do everything right ?

     

     

     


  6. hi!

     

    I have been using TWSocket erarlier to create listening sockets, but this is several years back, now i have a case where i need to make it work again.

     

    I got it to listen, but it eventually dies after some time, it could be 1 hour or  1 day.

     

    I do the following: 

     

    First i create the listening socket: 

     wsTradingWebHook.addr:='0.0.0.0';

     wsTradingWebHook.port:='80';
     wsTradingWebHook.Listen;

     

     

    When incoming I do the following:

     

    procedure TDataFunctions.wsTradingWebHookSessionAvailable(Sender: TObject;
      ErrCode: Word);
    var
      html : TStringlist;
      FMySocket : TWSocket;
    begin
      FMySocket := Twsocket.create(self);
      html  := TStringlist.Create;
      with FMySocket do
      try
        OnDataAvailable := wsTradingWebHookDataAvailable;

        HSocket := twsocket(sender).Accept;

        html.add('<html><head>');
        html.add('<title>Welcome to WhaleAlert</title>');
        html.add('</head><body>');
        html.add('Usage: <br>');
        html.add('{  "signal": "short",  "message": "short signal on 5 minutes" } <br>');
        html.add('{  "signal": "long",  "message": "long signal on 5 minutes" } <br>');
        html.add('</body></html>

        sendstr('HTTP/1.1 200 OK'#13#10);
        sendstr(format('Date: %s GMT+2'#13#10,[formatdatetime('ddd, dd mmm yyyy hh:mm:ss', date)]));
        sendstr('Server; myserver'#13#10);
        sendstr('Content-Type: text/html; charset=iso-8859-1'#13#10);
        sendstr(format('Content-length=%d'#13#10,[length(html.Text)]));
        sendstr(#13#10);
        sendstr(html.Text);
        sendstr(#13#10);
      finally
        freeAndNil(html);
      end;
    end;

     

    When I receive data from the server i handle it like this: ( I just want the json data received, so any data prior to the { and } will be deleted)

     

    I am unsure if i need the "TWSocket(sender).Free;" is needed, or the socket will just clean itself, if i try connect with a normal webserver i receive the "info" message, but the client still seem to wait for more data...i.e. the waiting circle keeps spinning...

     

    function TDataFunctions.ProcessWebHook(Received : string) : string;
    var
      PostCommand : string;
    begin
      result := '';
      if pos('POST',received) <> 0 then
      begin
        PostCommand := received;
        if (pos('{',PostCommand) <> 0) and
           (pos('}',PostCommand) <> 0) then
        begin
          Delete(postcommand, 1, pred(pos('{',PostCommand)));
          Result := PostCommand;
        end;
      end;

    end;

     

    procedure TDataFunctions.wsTradingWebHookDataAvailable(Sender: TObject;
      ErrCode: Word);
    var
      ProcessedCommand : string;
      Signal : string;
      TrayIcon  : TRzTrayIcon;

      UserData : ISuperObject;
      ReceivedJSON : AnsiString;
    begin
      try
        ProcessedCommand := ProcessWebHook(AnsiString(TSslWSocket(Sender).ReceiveStr));
        if (trim(ProcessedCommand) <> '') then
        try
          TrayIcon := frmMain.MyTrayicon;
          UserData := SO(ProcessedCommand);
          if userdata.s['signal'] = 'short' then
          begin
            Signal := userdata.s['message'];
            AddSignal(signal, false);
          end;

          if userdata.s['signal'] = 'long' then
          begin
            Signal := userdata.s['message'];
            AddSignal(signal, true);
          end;
        finally
          TWSocket(sender).Free;
        end;

        except
          AddSignal(ProcessedCommand, false,true);
        end;
    end;


  7. 10 hours ago, Angus Robertson said:

    OpenSSL connection errors simply mean some aspect of protocol negotiation has failed, they almost never tell you why or how to fix it. 

     

    I would make sure you set-up the SslContext similarly to InitSsl in OverbyteIcsSslHttpRest;.pas which is current best practice. Note SslCliSecurity in particular, which does all the hard for you in setting protocols, security and ciphers.

     

    Angus

     

    thanks. I will try this


  8. A bit more digging, obviously there are properties i need to set i think, but which one... 

     

    using linux plus gnutls-cli gave these results


     

    root@debian:/var/www/html# gnutls-cli stream.bybit.com:443
    Processed 128 CA certificate(s).
    Resolving 'stream.bybit.com:443'...
    Connecting to '143.204.47.65:443'...
    - Certificate type: X.509
    - Got a certificate list of 4 certificates.
    - Certificate[0] info:
     - subject `CN=*.bybit.com', issuer `CN=Amazon,OU=Server CA 1B,O=Amazon,C=US', serial 0x0383cade2595390d1e981419f44bf25f, RSA key 2048 bits, signed using RSA-SHA256, activated `2018-10-13 00:00:00 UTC', expires `2019-11-13 12:00:00 UTC', pin-sha256="7mhRzLK5Z7Q+sqQckWvcD8HwrOOA4L79f7roFhuTMqc="
            Public Key ID:
                    sha1:9503e077751ee70cd099b80c3e87e725a6a3ba68
                    sha256:ee6851ccb2b967b43eb2a41c916bdc0fc1f0ace380e0befd7fbae8161b9332a7
            Public Key PIN:
                    pin-sha256:7mhRzLK5Z7Q+sqQckWvcD8HwrOOA4L79f7roFhuTMqc=
    
    - Certificate[1] info:
     - subject `CN=Amazon,OU=Server CA 1B,O=Amazon,C=US', issuer `CN=Amazon Root CA 1,O=Amazon,C=US', serial 0x067f94578587e8ac77deb253325bbc998b560d, RSA key 2048 bits, signed using RSA-SHA256, activated `2015-10-22 00:00:00 UTC', expires `2025-10-19 00:00:00 UTC', pin-sha256="JSMzqOOrtyOT1kmau6zKhgT676hGgczD5VMdRMyJZFA="
    - Certificate[2] info:
     - subject `CN=Amazon Root CA 1,O=Amazon,C=US', issuer `CN=Starfield Services Root Certificate Authority - G2,O=Starfield Technologies\, Inc.,L=Scottsdale,ST=Arizona,C=US', serial 0x067f944a2a27cdf3fac2ae2b01f908eeb9c4c6, RSA key 2048 bits, signed using RSA-SHA256, activated `2015-05-25 12:00:00 UTC', expires `2037-12-31 01:00:00 UTC', pin-sha256="++MBgDH5WGvL9Bcn5Be30cRcL0f5O+NyoXuWtQdX1aI="
    - Certificate[3] info:
     - subject `CN=Starfield Services Root Certificate Authority - G2,O=Starfield Technologies\, Inc.,L=Scottsdale,ST=Arizona,C=US', issuer `OU=Starfield Class 2 Certification Authority,O=Starfield Technologies\, Inc.,C=US', serial 0x00a70e4a4c3482b77f, RSA key 2048 bits, signed using RSA-SHA256, activated `2009-09-02 00:00:00 UTC', expires `2034-06-28 17:39:16 UTC', pin-sha256="KwccWaCgrnaw6tsrrSO61FgLacNgG2MMLq8GE6+oP5I="
    - Status: The certificate is trusted.
    - Description: (TLS1.2)-(ECDHE-SECP256R1)-(RSA-SHA512)-(AES-128-GCM)
    - Session ID: E7:38:E2:7E:73:4B:E7:6C:46:1B:40:82:C5:79:B9:83:39:1C:70:E7:40:69:D2:51:9E:AB:E3:60:6B:83:02:30
    - Options: safe renegotiation,
    - Handshake was completed
    
    - Simple Client Mode:
    
    GET wss://stream.bybit.com/realtime HTTP/1.1
    Host: stream.bybit.com
    Upgrade: WebSocket
    Connection: Upgrade
    Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
    Origin: http://example.com
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13
    
    HTTP/1.1 101 Switching Protocols
    Connection: upgrade
    Date: Thu, 29 Aug 2019 21:39:13 GMT
    Upgrade: websocket
    Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
    X-Cache: Miss from cloudfront
    Via: 1.1 f00e3524edcdf61801454f2bb21e71ce.cloudfront.net (CloudFront)
    X-Amz-Cf-Pop: OSL50-C1
    X-Amz-Cf-Id: pF49hcINxgI6bYbor7C0cWbdBq8Q53_CA9kJ36JmwYi41ZIv2PPSyQ==


     


  9. after some digging, I decided to test indy, which gave some other error message

     

    Project Project17.exe raised exception class EIdOSSLUnderlyingCryptoError with message 'Error connecting with SSL.
    error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure'.

     

    what do i need to set in the SSLContext to get compatibility?


  10. 4 minutes ago, Angus Robertson said:

    10053 is aborted, can mean SSL negotiation failed or server does not like you.

     

    Angus

    obviously it does not like me.. Connection gets established, but it just immediately disconnects me.. i don't recevive a single byte from the server... the other server i used (bitmex) works like a charm,. but this "bybit" does not communicate.. im not sure what the difference is... websocket testing works normally.

     

    i am not sure if there is any properties i need to change which i missed

     


  11. 5 hours ago, Angus Robertson said:

    I think that says the client can not access their Websocket API, only the server is allowed to do so.  A common security measure.  Maybe you need an account with whoever offers that Websocket API?

     

    Angus

    I got a littlebit further now, but it seems im getting socketerror 10053 now, not sure where the culprit is here . but I will do some digging

     


  12. 9 hours ago, FPiette said:

    Maybe SendStrLF is the culprit:HTTP protocol need CRLF and the end of each request header line. And an additional CRLF at the end of header. The the document must follow, if any.

     

     

    nope, extra CRLF did not help. the function SendStrLF is just Sendstr procedure which just auto adds #13#10 to end of every line.. just to make it more readable...

     

    this connection works on another websocket service I used perfectly. however the answer from the support team was a bit cryptic to me when i don't really know all the tech stuff on SSL, but basically its just json communication over SSL socket...

     

    theire team answered this, which maybe a clue to whats happening ? 

     

    "We do not allow Cross-origin resource sharing (CORS) on our WebSocket API. Kindly use the server end to subscribe our Websocket API directly"


  13. 5 hours ago, Angus Robertson said:

    SSLMode is used internally by ICS components, it's not something applications normally need to worry about.  It determines whether the application makes or receives SSL connections, so a client must be sslModeClient or nothing will work. 

     

    Disconnection on idle connection is normal, unless you specify keep-alive, but don't know if that is part of the websockets specification. 

     

    Angus

     

    Aha!

     

    I don't really know what's going on here, but i compare with a chrome extension whats happening when i connect.. It says

    GET wss://stream.bybit.com/realtime HTTP/1.1
    Host: stream.bybit.com
    Connection: Upgrade
    Pragma: no-cache
    Cache-Control: no-cache
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
    Upgrade: websocket
    Origin: chrome-extension://pfdhoblngboilpfeibdedpjgfnlcodoo
    Sec-WebSocket-Version: 13
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.9,nb;q=0.8,no;q=0.7,nn;q=0.6,th;q=0.5
    Sec-WebSocket-Key: DdNU4DODQxp7NlzjW2U5xQ==
    Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

    this extension works.. so i try to send the following from my program

    SendStrLF(Format('GET %s HTTP/1.1', [TradeCouple]));
    SendStrLF('Accept-Encoding: gzip, deflate, br');
    SendStrLF('Accept-Language: en-US,en;q=0.9,nb;q=0.8,no;q=0.7,nn;q=0.6,th;q=0.5');
    SendStrLF('Cache-Control: no-cache');
    SendStrLF('Connection: Upgrade');
    SendStrLF('Host: stream.bybit.com');
    SendStrLF('Origin: chrome-extension://pfdhoblngboilpfeibdedpjgfnlcodoo');
    SendStrLF('Pragma: no-cache');
    SendStrLF('Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits');
    SendStrLF('Sec-WebSocket-Key: k1Yxf1UeGyDXhyKx2tmr9A==');
    SendStrLF('Sec-WebSocket-Version: 13');
    SendStrLF('Upgrade: websocket');
    SendStrLF('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36');

    this does not work, server just replies error 301... .

    really frustrating why its not working cause i can see no difference here 🙂

     


  14. hi!

      

    I am currently testing out websockets with TSSLWSocket, since i cannot find a good component which is free to handle this i had to create one myself.. it works on some server but the server i need to make it work with says i have to request on server, not client. I did see there was an option called SSLMode which can be set to either client or server, when I set it to server, i get a connection, but i don't get any further answer from the server after this,..

     is there another eventhandler for the data or am I missing something else here ?

     

    sidenote: i always get disconnected as well after a few seconds

     

  15. hi!

     

    I am currently testing out websockets with TSSLWSocket, since i cannot find a good component which is free to handle this i had to create one myself.. it works on some server but the server i need to make it work with says i have to request on server, not client. I did see there was an option called SSLMode which can be set to either client or server, when I set it to server, i get a connection, but i don't get any further answer from the server after this,..

    is there another eventhandler for the data or am I missing something else here ?


  16. Just now, David Schwartz said:

    property editors ... there are ways to disable them.

     

    I was trying to help you solve your audio playing problem.

     

    Instead, it looks like you're more interested in discussing politics of how libraries are packaged.

     

    If you have some beefs about a library, you need to take them up with the library's vendor.


    I can't help you with that stuff. And I have no problem with it either. 

    Pardon!,

     

    I did not mean to cause politics about it, just a friendly question on how to disable them if you knew,, I messaged the author but he did not answer, i'll try digging and see if i can disable this, and then i will try make it work:) 

     

    no harm meant 🙂 thanks for the suggestion

     


  17. 9 hours ago, David Schwartz said:

    You can use the OpenWire GUI tool it installs in the IDE to wire-up your data flows, or you can do it in code. Trust me when I say that you do NOT want to do it manually in code!

     

    But hey ... it'll solve your problem.

    I mean. this in the object inspector... i just doublecolick to toggle true and false.. amd now it opens this annoying dialog for every property that has some toggles, totally not cool

     

     

    image.thumb.png.95f2338316bb6d344a9431271fbf6c5b.png


  18. 9 hours ago, David Schwartz said:

    You can use the OpenWire GUI tool it installs in the IDE to wire-up your data flows, or you can do it in code. Trust me when I say that you do NOT want to do it manually in code!

     

    But hey ... it'll solve your problem.

    but still. I don't like the IDE modifications it does to my object inspector 😞 it's like forced upon me.. cannot uninstall that i think

×