Solved

IDTCPCLIENT SEND MESSAGE TO IDTCPSERVER TO INSERT ROW IN DATABASE.

Posted on 2006-07-15
3
640 Views
Last Modified: 2010-04-04
I HAVE 10 PROGRAM CLIENT CONNECTED IN MY PROGRAM SERVER, I DID THAT USING TIDTCPSERVER AND TIDTCPCLIENT. WORKS GOOD.

IN THE SERVER I HAVE OBJECT TQUERY TO UPDATE OR INSERT WHEN SOME CLIENT CONNECT OR DISCONNECT.

THE PROBLEM IS WHEN MORE THEN ONE CLIENT SEND MESSAGE TO SERVER FOR INSERT OR UPDATE AT THE SAME TIME.
I GOT ERROR IN MY TQUERY.
0
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 17115817
you will need to use a separate tquery and transaction for each client.
I would recommend creating them dynamicaly for each client when they connect
Otherwise you wii get thread errors as more than 1 client tries to use the tquery etc.

eg. inside the OnConnect event make an object that has your tquery inside it

type
    TClientSpecificData = class(TObject)
  private
      function GetCurrentProgressPercent: integer;
  public
      clientquery: TQuery;
      Constructor Create; override
      Destructor Destroy; override;
  end;

        { TClientSpecificData }

constructor TClientSpecificData.CreateWithSettings(ID_: string);
    begin
        Inherited Create;
        ClientQuery := TQuery.Create(nil);
// set query parameters here
    end;

destructor TClientSpecificData.Destroy;
    begin
        ClientQuery.Free;
        inherited;
    end;


procedure TfServerMain.IdTCPServer1Connect(AContext: TIdContext);
    begin
        AContext.Data := TClientSpecificData.Create;
    end;

procedure TfServerMain.IdTCPServer1Disconnect(AContext: TIdContext);
    begin
        if assigned(AContext.Data) then
        begin
            (AContext.Data as TClientSpecificData).Free;
            AContext.Data := nil;
        end;
    end;

procedure TfServerMain.IdTCPServer1Execute(AContext: TIdContext);
    var
        i: integer;
        S, S2: string;
        InCmd: string;
    begin
          InCmd := AContext.Connection.IOHandler.ReadLn;
// just an example
          (AContext.Data as TClientSpecificData).ClientQuery.SQL.Text := InCmd;
          (AContext.Data as TClientSpecificData).Open;
    end;
           
This is how I'd do it with the latest indy 10.
You can se how to do it with indy 9, or 10.0.52 on my demos page
http://sourceforge.net/projects/internetdemos

0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17115835
WHY YOU USE THIS LINE LIKE THIS: AContext.Connection.IOHandler.ReadLn; AND I USE THAT: AThread.Connection.ReadLn;

WHAT IS IOHANDLER?
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17117962
it depends on your version of Indy, with Indy 9 (the default) you just use .Connection.ReadLn
with Indy 10, there were some changes, and you use IOHandler
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 202
Delphi Seattle StructureView color 1 34
migrate this code to work on android 1 45
TAction.OnAfterExecute? 2 31
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question