Solved

IdTCPServer and IdTCPClient

Posted on 2004-04-16
2
1,228 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
[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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 97
Firemonkey DbLookupComboBox equivalent ? 2 79
Connect to SQL 2008 r2 server over the Internet 4 85
Posting a string with PostMessage 23 49
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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