Dear all,
after a long time searching and reading, i'm quite confused.
I have written, a piece of test code, which can be compiled on Windows 32bits as well as 64bit Linux. Under Windows, the test code shows the incoming messages, under Ubuntu, there will be nothing received (even if it is proofed, that my real application can send out multicast messages (which then can be received by the test code under Windows !!).
so at the end, i have a similar problem, as KIPROV has it.
Can somebody explain me, what I'm doing wrong ? Thanks in advance for every hint.
George
Here is my receiving code :
after a long time searching and reading, i'm quite confused.
I have written, a piece of test code, which can be compiled on Windows 32bits as well as 64bit Linux. Under Windows, the test code shows the incoming messages, under Ubuntu, there will be nothing received (even if it is proofed, that my real application can send out multicast messages (which then can be received by the test code under Windows !!).
so at the end, i have a similar problem, as KIPROV has it.
Can somebody explain me, what I'm doing wrong ? Thanks in advance for every hint.
George
Here is my receiving code :
Code:
// +-------------------------------------------------------------------------------------
program test;
// +-------------+---------+------+-------+-------------------------------------
// ¦ Date ¦ Fam.Ver ¦ Main ¦ Minor ¦ Description
// +-------------+---------+------+-------+-------------------------------------
// ¦ 2024-11-11 ¦ 0000 ¦ 00 ¦ 00 ¦ First release
// +-------------+---------+------+-------+-------------------------------------
{$APPTYPE CONSOLE}
// ¦ Units for Linux: Posix.Stdlib, Posix.SysStat, Posix.SysTypes, Posix.Unistd, Posix.Signal, Posix.Fcntl,
uses
System.SysUtils,
System.Types,
System.IOUtils,
System.Classes,
System.RTLConsts,
system.DateUtils,
System.SyncObjs,
IdSSLOpenSSL,
idSSlOpenSSLHeaders,
IdIPMCastClient,
IdSockethandle,
{$IFDEF linux}
Posix.Stdlib, Posix.SysStat, Posix.SysTypes, Posix.Unistd, Posix.Signal, Posix.Fcntl,
{$ENDIF }
{$IFDEF MSWINDOWS}
activex,
{$ENDIF }
IdGlobal;
const
EXIT_FAILURE = 1;
EXIT_SUCCESS = 0;
coAppname = 'ServerMCTest';
coFamilyVer = '0000';
coAppMajorVer = '0';
coAppMinorVer = '0';
coAppVersion = coFamilyVer+'.'+coAppMajorVer+'.'+coAppMinorVer;
coApptitle = coAppname+' - (c) 2024 Reference Data Lab GmbH';
// +--------------------------------------------------------------------------
// ¦ Type Definition for local Objects
// +--------------------------------------------------------------------------
type
TRunC = class(TComponent)
Private
public
{ Public-Deklarationen }
FBUSRX : TIdIPMCastClient;
Socket : TIdSocketHandle;
running : Boolean;
Procedure DoBusRXProcessing(Sender: TObject; const AData: TIdBytes; ABinding: TIdSocketHandle);
end;
// +--------------------------------------------------------------------------
// ¦ Globale Variablen
// +--------------------------------------------------------------------------
var
runc : TRunC;
// +--------------------------------------------------------------------------
// ¦ Linux Signal handling
// +--------------------------------------------------------------------------
{$IFNDEF MSWINDOWS}
procedure HandleSignals(SigNum: Integer); cdecl;
// 1. If SIGTERM is received, shut down the daemon and exit cleanly.
// 2. If SIGHUP is received, reload the configuration files, if this applies.
begin
case SigNum of
SIGTERM:
begin
runc.running := False;
end;
SIGHUP:
begin
// Reload configuration
end;
end;
end;
{$ENDIF}
procedure TrunC.DoBusRXProcessing(Sender: TObject; const AData: TIdBytes; ABinding: TIdSocketHandle);
Var
RXBuffer : String;
begin
{$IFDEF MSWINDOWS} coInitialize(nil);{$ENDIF }
// ¦ Einrichten
// ¦ Empfang der eingehenden XML Nachricht und überprüfung derselben
RXBuffer:=utf8String(Trim(BytesToString(AData)));
try
writeln(RxBuffer);
Except
end;
{$IFDEF MSWINDOWS} coUnInitialize;{$ENDIF }
end;
// +--------------------------------------------------------------------------
// ¦ Main Application
// +--------------------------------------------------------------------------
begin
runc:=Trunc.Create(nil);
writeln(coApptitle);
writeln('Version : '+coAppVersion);
writeln('STATUS : DEVELOPMENT 3');
// ¦ Einrichten FBUSRX
runc.FBUSRX:=tIdIPMCastClient.Create(runc);
runc.FBusRx.BufferSize:=1500;
runc.FBusrX.ReuseSocket:=rsTrue;
runc.Fbusrx.MulticastGroup:='224.0.0.1';
runc.FBusRx.DefaultPort:=38001;
runc.FBusRX.ReuseSocket:=rsTrue;
runc.FBusRX.OnIPMCastRead:=runC.DoBusRxProcessing;
runc.FBusRX.ThreadedEvent:=true;
runc.FbusRX.Bindings.Clear;
runc.Socket:=runc.FbusRX.Bindings.Add;
runc.Socket.IP:='0.0.0.0';
runc.Socket.Port:=38001;
runc.FBusRX.active:=true;
runc.running:=true;
{$IFDEF MSWINDOWS}
coinitialize(nil);
{$ENDIF}
// +------------------------------------------------------------------------
// ¦ Mainloop Windows
// +------------------------------------------------------------------------
{$IFDEF MSWINDOWS}
try
while runc.Running=true do
begin
sleep(10000);
end;
except
on E: Exception do
begin
Writeln(E.ClassName, ': ', E.Message);
runc.running:=False;
writeln('ERROR:'+E.ClassName+ ': '+ E.Message);
end;
end;
{$ENDIF}
// +------------------------------------------------------------------------
// +------------------------------------------------------------------------
// ¦ Mainloop Linux
// +------------------------------------------------------------------------
{$IFDEF LINUX}
try
while runc.Running=true do
begin
// deamon actual code
sleep(10000);
end;
ExitCode := EXIT_SUCCESS;
except
on E: Exception do
begin
ExitCode := EXIT_FAILURE;
runc.running:=false;
writeln('ERROR:'+E.ClassName+ ': '+ E.Message);
end;
end;
{$ENDIF}
// +------------------------------------------------------------------------
// +------------------------------------------------------------------------
// ¦ Aufräumen
// +------------------------------------------------------------------------
{$IFDEF MSWINDOWS}coUninitialize;{$ENDIF}
runc.Free;
end.
