Forum > General

How to get message from Server to Client. tIdTCPServer to TIdTCPClient [SOLVED]

(1/3) > >>

Nolan:
i want to get back some value sent from the Client to the server and I want the server to send something like a Response string.
Now the Client sends a command to the server to execute a function (This works good) now, in the same vein, i want a scenario where it returns something like 'Done' once the server has executed the program and it should show on the Label on the Client that everything is fine.

I have two source codes for the Client and the server Which is given thus :

Client


--- 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";}};} ---unit Client; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,  IdComponent, IdTCPConnection, IdTCPClient; type  TForm3 = class(TForm)    IdTCPClient1: TIdTCPClient;    Button1: TButton;    Label1: TLabel;    procedure FormCreate(Sender: TObject);    procedure Button1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; var  Form3: TForm3; implementation {$R *.dfm} procedure TForm3.Button1Click(Sender: TObject);begin  IdTCPClient1.Socket.WriteLn('SayHello');end; procedure TForm3.FormCreate(Sender: TObject);begin      IdTCPClient1:= TIdTCPClient.create(nil);      IdTCPClient1.Host := 'localhost';      IdTCPClient1.Port := 45000;      IdTCPClient1.Connect;end; end. 
So this is for the server

Server


--- 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";}};} ---unit Server; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,  IdCustomTCPServer, IdTCPServer, IdContext; type  TForm4 = class(TForm)    IdTCPServer1: TIdTCPServer;    procedure FormCreate(Sender: TObject);    procedure IdTCPServer1Execute(AContext: TIdContext);  private    { Private declarations }  public    { Public declarations }  end; var  Form4: TForm4; implementation {$R *.dfm} procedure SayHelloWorldMessageBox();begin  ShowMessage('Hello World!');end; procedure TForm4.FormCreate(Sender: TObject);begin      IdTCPServer1 := TIdTCPServer.Create(nil);      IdTCPServer1.DefaultPort := 45000;      IdTCPServer1.OnExecute:= IdTCPServer1Execute;      IdTCPServer1.Active:=true;end; procedure TForm4.IdTCPServer1Execute(AContext: TIdContext);    var    recv:string; begin        recv := AContext.Connection.Socket.ReadLn;    if recv = 'SayHello' then    begin          SayHelloWorldMessageBox();          AContext.Connection.IOHandler.Write('Done');    end; end; end.

Why does it not send a message from the Server to the Client to Display that "done", or basically, How do I display it to show everything is working good? New to this , i need Help here.

paweld:
https://forum.lazarus.freepascal.org/index.php/topic,60194.msg449534.html#msg449534

Nolan:

--- Quote from: paweld on August 06, 2022, 06:56:12 pm ---https://forum.lazarus.freepascal.org/index.php/topic,60194.msg449534.html#msg449534

--- End quote ---

I do not see anything like that there. I have been able to send commands from the Client to the server, now i want the server to send back some response to the Client.
Cannot get it to work.

paweld:
Type in a edit control "hello" or "2+2" and click "send" button.

In general, you need to start a thread after the client connection, which will read responses from the server.

MarkMLl:
Why are you asking in this forum when you're using Delphi? There's almost certainly more appropriate places... as you should have realised by now, since you've been doing the same thing for months.

Try recompiling with FPC/Lazarus and more of us might be interested... :-)

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version