Solved

IdTCPServer and IdTCPClient

Posted on 2004-04-16
2
1,223 Views
Last Modified: 2009-12-16
Hi guys,

There are multiple clients connected to my server, but the correct response does not always go to the correct Client, am I doing something wrong or am I suppose to use other components ?

See my code below :

Thanks !!

Pieter



CLIENT :

procedure TfrmMain.Button1Click(Sender: TObject);
var
  sResponse, sService : String;
  PDIni : TIniFile;
  iCounter : Integer;
  AStream : TStringStream;
begin
  {Read from INI File}
  PDIni := TIniFile.Create(ExtractFilePath(ParamStr(0) + 'conf\client.ini');

  iCounter := 1;

  try
    IdTCPClient1.Host := edtHost.Text;

    try
      IdTCPClient1.Port := StrToInt(edtPort.Text);
    except
      IdTCPClient1.Port := 7778;
    end;

    with IdTCPClient1 do
    begin

      Repeat
        sService := PDIni.ReadString('services', 'service_' + IntToStr(iCounter), '');

        Connect;

        while Connected do
        begin
          try
            AStream := TStringStream.Create('');

            WriteLn('service_status');
            WriteLn(sService);

            sResponse := ReadLn;

            mmLog.Lines.Add(sResponse);

            iCounter := iCounter + 1;

            AStream.Free;
          finally
            Disconnect;
          end;
        end;
      Until
        PDIni.ReadString('services', 'service_' + IntToStr(iCounter), '') = '';
    end;
  except
  end;
end;





SERVER :

procedure TMonitor.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  sRequest, sStatus : String;
begin
  try
    with AThread.Connection do
    begin
      try
        Repeat
          sRequest := ReadLn;

          if SRequest = 'service_status' then
          begin
            sServices := ReadLn;

            sStatus := GetServiceStat(PChar(sServices));

            if ((sStatus = 'UNKNOWN') or (sStatus = 'STOPPED')) then
            begin
              sStatus := 'N';
            end
            else if (sStatus = 'PAUSED') then
            begin
              sStatus := 'P';
            end
            else if ((sStatus = 'START/PENDING') or (sStatus = 'STOP/PENDING') or
              (sStatus = 'CONTINUE/PENDING') or (sStatus = 'PAUSE/PENDING')) then
            begin
              sStatus := 'B';
            end
            else
            begin
              sStatus := 'Y';
            end;

            WriteLn('[' + sServices + '][' + sStatus + ']');
          end;
        Until
          sRequest = '';
      finally
        Disconnect;
      end;
    end;
  except
  end;
end;

0
Comment
Question by:PieterJ
2 Comments
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 250 total points
ID: 10841299

   On the Server you should have TIdTCPServer component.

   Then add on the form TIdThreadMgrDefault VCL - found on Indy Misc tab. Select the TCP server and it has propery ThreadMgr - select the TIdThreadMgrDefault object there.
0
 

Author Comment

by:PieterJ
ID: 10841335
Hi Ivanov,

Thanks for the quick reply !!

Sorry, I forgot to mention that I do have a IdThreadMgrDefault Component in my Service, and have selected it in the IdTCPServer's Object Inspector.

Thanks

Pieter
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse url in delphi 2 194
Internet Explorer View Settings Question 15 111
Delphi selector screen 2 78
Delphi: barcode reading on android platform 1 26
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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