Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Feb : TIdUDPServer, problem
| Subject: | TIdUDPServer, problem |
| Posted by: | "Harald" (noma..@noname.dk) |
| Date: | Tue, 1 Feb 2005 21:43:55 |
Hi
I have made this small test program but it does not work. The program only
receives 50% of the UDP packets that is send to it, even if I only send a
packed every 1-2 seconds only about 50% is received. When I close the
program, it takes about 5 seconds before it disappears from the process list
in windows XP.
/HK
--------------------------------
unit UdpTestUnit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPServer;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure PutInMemo(Text : string);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
TUDPThread = class(TThread)
private
{ Private declarations }
UDPServer: TIdUDPServer;
Buffer : string;
BytesRead : integer;
procedure SendData;
protected
procedure Execute; override;
public
constructor Create(aPort: integer);
end;
var
Form1: TForm1;
UDPThread : TUDPThread;
implementation
{$R *.dfm}
// ****************************** BEGIN Thread
****************************************************************
constructor TUDPThread.Create(aPort: integer);
begin
inherited Create(False);
FreeOnTerminate:=true;
UDPServer:=TIdUDPServer.Create(nil);
UDPServer.DefaultPort:=aPort;
end;
procedure TUDPThread.SendData;
begin
Form1.PutInMemo(Buffer);
end;
procedure TUDPThread.Execute;
begin
UDPServer.Active:=true;
SetLength(Buffer,1024);
while not Terminated do
begin
BytesRead:=UDPServer.ReceiveBuffer(Buffer[1],1024,1000);
if BytesRead>0 then
Synchronize(SendData);
end;
UDPServer.Active:=false;
UDPServer.Free;
end;
// ****************************** END Thread
****************************************************************
procedure TForm1.PutInMemo(Text : string);
begin
Memo1.Lines.Add(Text);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
UDPThread:=TUDPThread.Create(5065);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UDPThread.Terminate;
end;
end.