![]() |
TIdTCPClient - parallel Verbindungen aufbauen ?
Hallo,
ich habe eine kleine App enwickelt was Anwender erlaubt Industriecontroller zu bedienen. Max 16 Stck. Kommunikation geht, läuft über TIdTCPClient. Und soweit auch kein Problem. Aber.. bei 16 Controller muss no 16 zzt abwarten bis 1..15 ausgeführt ist. Was etwa 1-2 Min dauert. Deshalb meine Frage: wie mache ich das "parallel" ? Ich vermute mit TThreads. Eine kurze Beispiel währe genug. Was ich jetzt habe.. dieses Procedure ist über eine Loop (i = 1..16) ausgeführt.
Delphi-Quellcode:
{
-------------- Action loop for controller -------------- This is run up to 16 times.. } procedure TpopForm.do_some_action(printerid : integer); const port: Integer = 3000; var TCPClient: TIdTCPClient; s : string; begin try try TCPClient := TIdTCPClient.Create(nil); TCPClient.Port := port; TCPClient.Host := controllers[printerid].IP; // IPs stored in an array TCPClient.UseNagle:=False; TCPClient.RecvBufferSize := 1024; TCPClient.SendBufferSize := 1024; TCPClient.Connect; // NOW SEND THE STRING TO RESET INK LEVEL TCPClient.Write('MYCOMMAND#'); // commands and responses terminate by "#" repeat s := TCPClient.ReadLn('#'); until LeftStr(s, 3) = 'RES'; // final response starts with "RES" except end; finally TCPClient.Disconnect; tcpclient.Free; end; end; |
AW: TIdTCPClient - parallel Verbindungen aufbauen ?
Kleine Korrekturen:
Delphi-Quellcode:
den leeren except Block habe ich mal dezent entfernt :)
procedure TpopForm.do_some_action(printerid : integer);
const port: Integer = 3000; var TCPClient: TIdTCPClient; s : string; begin TCPClient := TIdTCPClient.Create; // vor try, ohne (nil) möglich try TCPClient.Port := port; TCPClient.Host := controllers[printerid].IP; // IPs stored in an array TCPClient.UseNagle := False; // TCPClient.RecvBufferSize := 1024; nicht notwendig // TCPClient.SendBufferSize := 1024; nicht notwendig TCPClient.Connect; TCPClient.Write('MYCOMMAND#'); repeat s := TCPClient.ReadLn('#'); until LeftStr(s, 3) = 'RES'; finally // TCPClient.Disconnect; Free führt Disconnect aus TCPClient.Free; end; end; |
AW: TIdTCPClient - parallel Verbindungen aufbauen ?
Zitat:
|
AW: TIdTCPClient - parallel Verbindungen aufbauen ?
Ich danke für die Änderungen bzw Verbesserungen. Ich bin sicher es gibt in mein Programm mindestens 1024 davon ;) Bin halt nur "amateur".
Aber, immer nocht nicht Parallel. ;) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:57 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz