UDPServer Assign Event Handler Not Working

Giganews Newsgroups
Subject: UDPServer Assign Event Handler Not Working
Posted by:  Adrian (heyadrian…@hotmail.com)
Date: 11 Mar 2008

Hello all,

I am trying to make a DLL that simply broadcasts a message out
using UDP and through a custom port. I assign a custom function
to the event OnUDPRead but it never gets triggered, and I am not
sure why not...

--------------------------------------------------------

type TDummyClass = class
  public
    procedure UDPServerRead(Sender: TObject; AData: TBytes; ABinding: TIdSocketHandle);
end;

var
  UDPServer: TidUDPServer;
  DummyClass: TDummyClass;

procedure TDummyClass.UDPServerRead(Sender: TObject; AData: TBytes; ABinding: TIdSocketHandle);
begin
  Showmessage('Got here!!');
end;

procedure InitializeDLL; cdecl; export;
begin
  DummyClass := TDummyClass.Create;

  UDPServer := TidUDPServer.Create(nil);
  UDPServer.ThreadedEvent := True;
  UDPServer.BroadcastEnabled := True;
  UDPServer.Active := True;
  UDPServer.OnUDPRead := DummyClass.UDPServerRead;
  UDPServer.DefaultPort := 33;
end;

procedure Broadcast(MessageToBroadcast: ShortString; Port: Integer); cdecl; export;
begin

I know broadcasting works, as I have a seperate application to
show them when they are received - its just when the UPDServer
inside the DLL receives broadcasts it does nothing (its OnUPDRead
event is not activated

  UDPServer.Broadcast(xxx, aaa);
end;

Why does this not work? The DLL sends broadcasts successfully (I
have removed the broadcasting code for clarity), but it does not
fire the OnUDPRead event when it receives broadcasts?

Thanks,
Adrian ;)

Replies