Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 May : Causing Indy OnUDPRead Event to fire
| Subject: | Causing Indy OnUDPRead Event to fire |
| Posted by: | "Gary Hopwood" (h..@fwsite.com) |
| Date: | Thu, 19 May 2005 18:19:59 |
I am writing a dll that dynamically creates an Indy UDP server to listen for
inbound messages that are put in a TThreadlist until requested by the using
program. I define it like so
Type MyReader = Class(TIdUDPServer)
procedure GetIt(Sender : TObject; AData: TStream;
ABinding: TIdSocketHandle);
end;
.
.
Procedure MyReader.GetIt(Sender : TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
k : Integer;
StrBuf : String;
MPtr : MsgPtr;
begin
try
k := AData.Size;
AData.Seek(0,0);
SetLength(StrBuf, k);
AData.Read(StrBuf[1], k);
except
exit;
end;
// Now Build a Queue record and save
New(MPtr);
MPtr.DateTimeIN := Now;
MPtr.Processed := False;
MPtr.Encrypted := True;
MPtr.MsgIN := StrBuf;
InQueue.Add(MPtr);
end;
The DLL has a function which must be called first by the using program
called Init and that is where the thing gets setup.
function Init() : Integer; stdcall;
Begin
try
InQueue := TThreadList.Create;
UDPS := MyReader.Create(nil);
UDPS.DefaultPort := 8188;
UDPS.Buffersize := 32767;
UDPS.OnUDPRead := UDPS.GetIt;
UDPS.Active := True;
Result := 0;
except
Result := 99;
exit;
end;
end;
The problem is that the OnUDPRead event is not firing until I close the
instance that is created in the above routine - then it fires and reads it
right in.
function CloseDLL() : Integer; stdcall;
begin
try
UDPS.Active := False; // THIS CAUSES THE READ EVENT TO FIRE
UDPS.Free;
InQueue.Clear;
InQueue.Free;
Result := 0;
except
Result := 99;
end;
end;
The whole dll - works perfectly if I use the Indy TCP components.
Can someone enligthment on how to get the OnUDPRead event to fire and get
the associated procedure to run just like it does when you drop the
component on a form.
Thanks