Solved

IDTCPCLIENT SEND MESSAGE TO IDTCPSERVER TO INSERT ROW IN DATABASE.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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