Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IDTCPCLIENT SEND MESSAGE TO IDTCPSERVER TO INSERT ROW IN DATABASE.

Posted on 2006-07-15
3
Medium Priority
?
664 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline

885 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