Link to home
Create AccountLog in
Delphi

Delphi

--

Questions

--

Followers

Top Experts

Avatar of rafaelrgl
rafaelrgl

Connection Client - Server and Server - Client using TidCmdTcpClient and TIdCmdTcpServer From Indy 10
   Ok, experts, he we go again, I'm tired trying to bring some solutions for my project, I really need your help with this. My biggest problem is about connection client-server and server-client. I mean, I'm using delphi 7 and trying to build my application using TIdCmdTcpClient and TIdCmdTcpServer.

    Also, i'm using commandhaldle from the component TidCmdTcpServer/TidCmdTcpClient.
   
    The client side sometimes need's send message to the server.
     
    This will be like this: The server controls a lot user, sending message to the clients like close windows, or shutting down the pc, or blocking the user from using the pc, but that's not the problem
   
    1) The client received the messages from the server normally, but sometimes when the user do some kind of active on the machine, than it has to send a message to the server telling what happening, but I don't know how to send message back to the server.

    2) Handle the server about wich is the right client to send message.

     3) How to do broadcast using this command, I'm meam, how to send message to all pc's connected on the server.






Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of developmentgurudevelopmentguru🇺🇸

 You may be trying to use one protocol when it would make better sense to use more than one.  If you stick with your current setup you would need to take notes when a connection is made on the server.  These notes could include the IP address of the client, user name, etc.  Then when you need to send a message to a client you will have what you need to identify the correct client.  Gnerally the individual connections are handled as separate threads and you can design your thread with a method allowing you to send a message to that individual client.  In this design you would need to loop through your list and send a message to each one to enact a broadcast.

As an alternatvie for the broadcast check out Indy UDP at these links.
http://delphi.about.com/library/weekly/aa101105a.htm
http://delphi.about.com/od/adptips2005/qt/udpvstcp.htm

Avatar of rafaelrglrafaelrgl

ASKER

So, could you give a exemplo what i will have to add in my thread to allow send message to the client. I can find the client adding the ip, that's ok. sending message back is a problem to me, pls help me on this. I'm doing this way:

///////////////////////////////////////////

Type
  PConexao = ^TConexao;
  TConexao = record
    IP, User, Maq, Ver, PathInstall : ShortString;
    Client : ??????????/ what type will be here???
  end;
////////////////////////////////////////////


procedure TFPrinc.IdCmdTCPServer1Connect(AContext: TIdContext);
begin
   { THESE TWO LINES ARE CRITICAL TO MAKING WORK WITH SSL! }
   if (AContext.Connection.IOHandler is TIdSSLIOHandlerSocketBase) then
   begin
     TIdSSLIOHandlerSocketBase(AContext.Connection.IOHandler).PassThrough:= False;
   end;
            //when the client connects
            ConAux.IP := AContext.Connection.Socket.Binding.PeerIP;
            ConAux.Client := ?????????? That's where i will handle to msg back?

end;

ASKER CERTIFIED SOLUTION
Avatar of developmentgurudevelopmentguru🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

If you take a look at the code that i send you above you will the the var Client on ConAux.Client, that's where i want to handle the client, but i don't know how to do it, Can you show:

Maybe will be: ConAux.Client := Acontext;?????, but that's not work, I test already

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


I don't know how to send message, but this will be the function to send to all clients:


Procedure  TFPrinc.SendAll(msg : string);
var
  i: integer;
  ConAux: PConexao;
begin
    for i:= 0 to conn.Count -1 do
    begin
       ConAux := PConexao(conn[i]);
       ?????Send message here, don't know the command???????
    end;
End;

waiting answer!...

SOLUTION
Avatar of TheRealLokiTheRealLoki🇳🇿

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

testing solution

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


i'm not using IdTcpServer, I'm using IdCmdTcpServer from indy 10.

the only thing that i'm finding that maybe can be something, lol. Is this function:

IdCmdTCPServer1.IOHandler.MakeClientIOHandler

waiting answering...

i'm not using IdTcpServer, I'm using IdCmdTcpServer from indy 10.

waiting answering...

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


guys, i'm not using idtcpserver, i'm using tidcmdtcpserver from indy 10, pls i'm waiting some comments.

what happening, waiting answer.
Delphi

Delphi

--

Questions

--

Followers

Top Experts

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.