Jump to content

Dmytro Lendel

Members
  • Content Count

    18
  • Joined

  • Last visited

Community Reputation

1 Neutral
  1. Dmytro Lendel

    how to Properly check if Twsocket Tcp client is still connected ?

    I am sorry, one more question if you please. What is different between OnError, OnSocksError, OnBgException events? What I need to use? Regards, Dmytro
  2. Dmytro Lendel

    how to Properly check if Twsocket Tcp client is still connected ?

    O! Thank you! Will try. Regards, Dmytro
  3. Dmytro Lendel

    how to Properly check if Twsocket Tcp client is still connected ?

    Hello, Thank you My devices have owner ethernet module and I can`t control it. I just can set timeout in it. After client timeout event, module generate new connection (and does not close old connection manually) to the server. I see 2 connections. Again and again My application keeps active socket pointer in internal structure. With new connection I can recognize device by ID and update socket pointer with new value. Total amount of device is always 48 in the logic list but it can be 457 in FWSocketServer.ClientCount 🙂 As far as I can see, I can use sentstr for all clients and onError event will occurs for invalid clients. Right? Than I`ll need close socket. Regards, Dmytro Lendel
  4. Dmytro Lendel

    how to Properly check if Twsocket Tcp client is still connected ?

    Hello, I have 45 devices connected to the Socket Server through internet. Internet connection is not stable and my devices connected again. In the log I found Client connected. Remote: 10.30.10.1/6146 Local: 10.30.10.199/1001 Client connected. Remote: 10.30.10.1/61949 Local: 10.30.10.199/1001 Client connected. Remote: 10.30.10.1/6666 Local: 10.30.10.199/1001 How I can check active connections? Because in summary I have 128 clients but only 48 is real Is code below will be correct? for i:=0 to FWSocketServer.ClientCount-1 do if (FWSocketServer.Client as TTcpSrvClient).State=wsInvalidState then FWSocketServer.Client.CloseDelayed else if FWSocketServer.Client.SendStr('test')<0 then try FWSocketServer.Client.CloseDelayed; finally end; Regards, Dmytro Lendel P.S. I can`t login to the forum and can`t reset my password. I do not know why
  5. Dmytro Lendel

    THWClient.RequestDone

    Thank you.
  6. Hello, Where I can find error description for ErrCode in OnRequestDone event? THWClient.RequestDone(Sender: TObject; RqType: THttpRequest; ErrCode: Word); Regards, Dmytro
  7. Ok. May be you are right. No reason to discovery the bike Thank you
  8. Hi OverbyteIcsThrdSrvV2 will be good example? Can I do like in OverbyteIcsThrdSrvV2? { TClientThread is our worker thread class. Each time a client connect, a } { new TClientThread is instanciated and client socket attached to it so } { events are processed in the thread's context. } { Remember that multithreading requires synchronization, specially when } { updating GUI or accessing shared data. } { TClientThread uses OnDisplay event to display data on the application } { main form. Synchronization is automatically done. } {$M+} { Needed for Published to take effect } TClientThread = class(TThread) private FWSocket : TWSocket; { Reference to client socket } FMsg : String; { Message to be displayed } FOnDisplay : TDisplayProc; { Event variable } FThreadAttached : Boolean; { TRUE once socket attached } FCritSect : TRTLCriticalSection; procedure DisplayMsg; { Synchronized procedure } public constructor Create(Suspended : Boolean); destructor Destroy; override; procedure Execute; override; { Main method } procedure Display(const Msg : String); { Takes care of synchroniz. } published property WSocket : TWSocket read FWSocket write FWSocket; property ThreadAttached : Boolean read FThreadAttached write FThreadAttached; property OnDisplay : TDisplayProc read FOnDisplay write FOnDisplay; end; { TThrdSrvClient is the class which will be instanciated by server } { component for each new client. N simultaneous clients means N } { TThrdSrvClient will be instanciated. Each being used to handle only a } { single client. } { We can add any data that has to be private for each client, such as } { receive buffer or any other data needed for processing. } TThrdSrvClient = class(TWSocketClient) protected procedure WndProc(var MsgRec: TMessage); override; procedure WMStartCnx(var Msg: TMessage); message WM_START_CNX; public ClientThread : TClientThread; RcvdLine : String; ConnectTime : TDateTime; procedure StartConnection; override; end;
  9. Hi, Thank you so much!
  10. Hello, I need help if you please We used socked server with our devices many years and it works nice. Protocol is ASCII and very simple. Now we start to use thread socked server because we need to make same heavy queries sometimes depends on device`s request. Query is http request with get and post methods. My question is following. Is it safety to call http request from TWSocketThrdClient onClientdata event? As far as I can see TWSocketThrdClient will create own thread inside Socked thread. Correct? What is best way to implement this logic? Hope, somebody will help me Thank you Regards Dmytro
  11. Hello, Problem after calling function HttpPostByStr Next line from client generate exception Invalid point operation and after some time server is crashing I can`t to understand why. Regards, Dmytro
  12. Hello, I changed a little simple OverbyteIcsThrdSrvV2_1 I need create dynamic http request in processdata event and send answer to Client procedure TTcpSrvForm.ProcessData(Client : TThrdSrvClient); Err:String; begin if Copy(Trim(Client.RcvdLine),1,3)='$RQ' then begin Err:=''; HttpPostByStr('{"serialNumber":"98D863E0F226","state":"No data for you"}',Err); Display(IntToHex((Client as TThrdSrvClient).ThreadID,8)+' '+ err); end; end; function HttpPostByStr(SJson: String;var Resp:String):Boolean; var FIDHttp:THttpCli; JsonToSend: TStringStream; ResivdToSend: TStringStream; MyResp,get_url: string; begin Result:=False; MyResp:=''; get_url:='http://194.44.237.46:8087'+'/api/points/states'; JsonToSend := TStringStream.Create('['+SJson+']', TEncoding.UTF8); JsonToSend.Position := 0; ResivdToSend:=TStringStream.Create; FIDHttp:=THttpCli.Create(nil); FIDHttp.ContentTypePost := 'application/json-patch+json'; FIDHttp.Username:='username'; FIDHttp.Password:='pass'; FIDHttp.serverauth:=httpAuthBasic; FIDHttp.URL:=get_url; FIDHttp.SendStream:=JsonToSend; FIDHttp.RcvdStream:=ResivdToSend; Resp:=''; try try FIDHttp.Post; Result:=True; except on E: Exception do begin Resp:= e.Message; end; end; finally ResivdToSend.Seek(0, 0); //Resp='' then Resp:=ResivdToSend.DataString; ResivdToSend.Free; JsonToSend.Free; FIDHttp.Free; end; end; It`s working, but after closing application exception in OverbyteIcsWSocket "Invalid pointer operation" destructor TCustomLineWSocket.Destroy; begin if FRcvdPtr <> nil then begin FreeMem(FRcvdPtr, FRcvBufSize); <-- here FRcvdPtr := nil; FRcvBufSize := 0; end; inherited Destroy; end; Where is my mistake? Regards Dmytro
  13. Dmytro Lendel

    how to send byte array with TWSocketClient

    Thank you!
  14. Dmytro Lendel

    how to send byte array with TWSocketClient

    Hello, How to send byte array with TWSocketClient? I have byte array buffer: array[1..133] of byte I found method Send but it`s working with TBytes PFirmWare = ^TFirmWare; TFirmWare = record buffer: array[1..133] of byte; end; -------------- procedure THWClient.SendXModemLine(Line: integer); var buffer : TBytes; begin if Assigned(SocketClient) then begin if (SocketClient.State=wsConnected) then begin SetLength(buffer, Length(PFirmWare(FXmodemFile.Items[Line])^.buffer)); Move(PFirmWare(FXmodemFile.Items[Line])^.buffer, buffer, Length(PFirmWare(FXmodemFile.Items[Line])^.buffer)); SocketClient.Send(buffer,Length(buffer)); <-- AV is here end; end; end; Can you help me please? Regards Dmytro
  15. Dmytro Lendel

    SSL_CTX_use_certificate:ee key too small

    Hello, I sent request to the vendor about TLS support. I can`t to understand how they implemented it. Hope will have answer soon Thank you! Dmytro
×