Forum > General

Q: System code for Indy Sockets, extra parameters/values from server to client.

(1/2) > >>

pascalbythree:
Hey to Freepascal Forum Members,

TIdCmdTCPServer code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//******************************************************************************    NewCmd                            := IdCmdTCPServer.CommandHandlers.Add;    NewCmd.Command                    := '[SYSTEM_ERASE]';    NewCmd.OnCommand                  := @WVW_HANDLER_SYSTEM_ERASE;    NewCmd.ExceptionReply.NumericCode := 550;    NewCmd.Description.Text           := 'Erase MCU';     NewCmd.Disconnect                 := False;        NewCmd.ParseParams                := True;//****************************************************************************** procedure TApplication.WVW_HANDLER_SYSTEM_ERASE(ASender: TIdCommand);begin  clrscr;  Wr('WVW_HANDLER_SYSTEM_ERASE...',green,black);  ASender.Response.Add('[SYSTEM_ERASE_DONE]');    ASender.SendReply; end;
TidCmdTCPClient code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.IdCmdTCPClient1CommandHandlers0Command(  ASender: TIdCommand);begin//SYSTEM_ERASE_DONEMemo1.Lines.Append('[SYSTEM_ERASE_DONE]');end; 
Question, does anybody know howto send strings with variables in it from this Server to Client?
Inside the indy class framwork, with these procedures ?

Greets, PascalByThree.

Thaddy:
Reminds me of this:
http://bobby-tables.com/img/xkcd.png
( Note I have not really used Indy for over 15 years, but there are experts, including a Guru Indy specialist, forum member and Indy maintainer that can answer this)

pascalbythree:
More alike this:

https://stackoverflow.com/questions/33172408/tidcommandhandler-how-to-construct-commands


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---case RadioGroup1.ItemIndex of  0: IdTCPClient1.IOHandler.WriteLn('COLOR SET|BLUE');  1: IdTCPClient1.IOHandler.WriteLn('COLOR SET|RED');  2: IdTCPClient1.IOHandler.WriteLn('COLOR SET|YELLOW');end;

Except that there commands require to much CommandHandlers procdures.

Is there a way to make it parse variables ? Instead of  fixed commands ?

Greets, Wouter

Remy Lebeau:

--- Quote from: pascalbythree on March 25, 2023, 06:08:19 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TApplication.WVW_HANDLER_SYSTEM_ERASE(ASender: TIdCommand);begin  clrscr;  Wr('WVW_HANDLER_SYSTEM_ERASE...',green,black);  ASender.Response.Add('[SYSTEM_ERASE_DONE]');    ASender.SendReply; end;
--- End quote ---

FYI, you don't need to manually call ASender.SendReply() in this example.  It will be called automatically after the OnCommand handler exits, if a reply has not been sent yet.

Other than that, why is your server replying to the client by sending it another command?  Why not send a numeric/text code ala ASender.Reply.SetReply() instead?  Why is your client using TIdCmdTCPClient instead of using a standard TIdTCPClient with its SendCmd() method?  Do you really need fully asynchronous handling on both sides of the connection?


--- Quote from: pascalbythree on March 25, 2023, 06:08:19 pm ---does anybody know how to send strings with variables in it from this Server to Client?

--- End quote ---

I'm not really sure I understand what you are asking for.  Are you looking for something like this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TApplication.WVW_HANDLER_SYSTEM_ERASE(ASender: TIdCommand);begin  clrscr;  Wr('WVW_HANDLER_SYSTEM_ERASE...',green,black);  ASender.Response.Add('[SYSTEM_ERASE_DONE] String1 String2 String3');end;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.IdCmdTCPClient1CommandHandlers0Command(  ASender: TIdCommand);begin  //SYSTEM_ERASE_DONE  Memo1.Lines.Append('[SYSTEM_ERASE_DONE]');  Memo1.Lines.AddStrings(ASender.Params);end;
If you were to use TIdCommand.Reply.SetReply()/TIdTCPClient.SendCmd() instead, then it could look something more like this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TApplication.WVW_HANDLER_SYSTEM_ERASE(ASender: TIdCommand);begin  clrscr;  Wr('WVW_HANDLER_SYSTEM_ERASE...',green,black);  ASender.Reply.SetReply('OK', '');  ASender.Reply.Text.Add('String1');  ASender.Reply.Text.Add('String2');  ASender.Reply.Text.Add('String3');end;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...IdTCPClient1.SendCmd('[SYSTEM_ERASE]', 'OK');Memo1.Lines.Append('[SYSTEM_ERASE_DONE]');Memo1.Lines.AddStrings(IdTCPClient1.LastCmdResult.Text);...

pascalbythree:
Thank you alot Remy Lebeau, it got to work so far!

Check.... these are my 2 systems running on a Raspberry ZERO

Both have the Freepascal compiler installed in the LITE version, from ARM to AVR

Including screenshot form my Delphi 10 Application.

Problem: It does not re-connect, i must always restart the WIN32 Client and my Console application before it connect again.

Does anybody have source code how i can stable reconnect in the same instance ? For the IdCmdTCPServer ?

Greets, Wouter

 :-X

PS: My console app has a indy socket at the back.

Is this going to work out on a forum? Or do i need to reply with more clearance?

Rack mounted design on picture.

Navigation

[0] Message Index

[#] Next page

Go to full version