Jump to content

plastkort

Members
  • Content Count

    36
  • Joined

  • Last visited

Everything posted by plastkort

  1. plastkort

    Webhook example

    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.
  2. plastkort

    VCL component issue

    im trying to use a very old component i made for delphi 7 back in the days, i havent touched it for many years. but it installed ok without a problem, however when i go to the component list and want to add it.. it seems to be "faded" and cannot be added... why is it so ? it works if i create a new application and try to add it...
  3. 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;
  4. I can take a look at TWSocketServer, I think i used it before, but maybe 6-7 years ago. As a sidenote, i think the shutdown(2) and close did the trick i think. program still accepting connections after 2 days.
  5. 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
  6. 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 ?
  7. I looked at it, and it seems it needed a HTML folder, I just need to answer a few lines. this works for me. for a short time. but the listening socket seems to die
  8. 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
  9. plastkort

    TSSLWSocket (repost)

    thanks. I will try this
  10. plastkort

    TSSLWSocket (repost)

    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==
  11. plastkort

    TSSLWSocket (repost)

    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?
  12. plastkort

    TSSLWSocket (repost)

    ok, but this gets disconnected instantly, the onconnect and ondisconnect gets triggered, but thats it it works fine ifi try another service to connect
  13. plastkort

    TSSLWSocket (repost)

    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
  14. plastkort

    TSSLWSocket (repost)

    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
  15. plastkort

    TSSLWSocket (repost)

    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"
  16. plastkort

    TSSLWSocket (repost)

    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 🙂
  17. 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 ?
  18. plastkort

    TSSLWsocket and websockets

    posted this in ICS thread.. how do i delete this ?
  19. Have been digging everywhere around the web for a solution that allows me to play simple wave files simultaneously... i found some examples but none of them works soundplay works with only a single file at a time even if i create them in a TThread, i tried to change and tweak it, but for now i have given up, so now I am asking if anyone of you have experience with this before, any library that can help, i am not really interrested in using an external program as a via shell execute since it can slow things down. would be perfect if there was a working windows API that just plays the sound and with no hassle.. mciSendString does not work at all either for me
  20. plastkort

    Playing multiple wave files simultaneously

    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
  21. plastkort

    Playing multiple wave files simultaneously

    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
  22. plastkort

    Playing multiple wave files simultaneously

    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
  23. plastkort

    Playing multiple wave files simultaneously

    yeah it also modified my entire delphi IDE 😕 not cool
  24. plastkort

    Playing multiple wave files simultaneously

    A working solution is actually more important, i will take a look at mitovs library
  25. plastkort

    Playing multiple wave files simultaneously

    aparently this could work but it seems not to work in delphi by some reason ? uses mmSystem; mciSendString('play D:\test.wav',nil,0,0); i seen other examples in c++ this works.. but in delphi it does not
×