Solved

IDTCPCLIENT SEND MESSAGE TO IDTCPSERVER TO INSERT ROW IN DATABASE.

Posted on 2006-07-15
3
617 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 186
find a node in VST 2 64
Delphi inherited method 6 63
PHP preg_replace code convert to Delphi 14 35
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now