A pc broadcasts every second to other computers on the network. Works fine, except with irregular intervals there is no transmission for 5 seconds. Then it resumes as nothing has happened.
I tried to move the exe file to another pc (to rule out errors on programming pc), but still the same weird result. Here is the screenshot of received data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
Note data is missing from 24 to 29. It will also be missing later on (not shown here). I have no idea why.
Here is the source code:
unit UClientServer;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, IdUDPServer,
IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient, IdGlobal, IdSocketHandle;
type
TForm1 = class(TForm)
Client: TIdUDPClient;
Tx: TLabeledEdit;
BtnStartC: TButton;
BtnStopC: TButton;
Timer1: TTimer;
procedure BtnStartCClick(Sender: TObject);
procedure BtnStopCClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
TimerTick: word = 0;
procedure TForm1.BtnStartCClick(Sender: TObject);
begin
Client.Active:= false;
Client.Host:= '192.168.1.255'; //Broadcast to all computers on this network...
Client.Port:= 8100; //...using this port
Client.Active:= true;
end;
procedure TForm1.BtnStopCClick(Sender: TObject);
begin
Client.Active:= false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
//Transmits every second a test message (1,2,3 and so on)
var
S: string;
begin
if Client.Active then
begin
inc(TimerTick);
Tx.Text:= IntToStr(TimerTick)+' ';
S:= S + Tx.Text;
if TimerTick mod 10 = 0 then S:= S + #13#10;
Client.Send(S);
end;
end;
end.
Programming tool: Embarcadero® Delphi 10.2 Tokyo Version 25.0.26309.314