Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Jun : Indy UDP BroadCast
| Subject: | Indy UDP BroadCast |
| Posted by: | "Gurur" (gurr..@rediffmail.com) |
| Date: | Thu, 31 May 2007 22:40:28 |
hi friends,
I m a new Indy user. I want to broadcast messages using IdUDPServer
and IdUDPClient.
I have written a small piece of code, but I m unable to find my
mistake.I have placed my IdUDPServer on Server and IdUDPClient on
CLient.
THe message must be broadcasted by Server and Client must be able on
receive it on a particular port.
SERVER
-------------
const
UDPDefaultPort = 8760;
procedure TForm1.FormCreate(Sender: TObject);
begin
HostName.Caption := UDPServer.LocalName;
HostAddress.Caption := GStack.LocalAddress;
UDPServer.DefaultPort := UDPDefaultPort;
Port.Caption := IntToStr(UDPServer.DefaultPort);
// Port.Caption := IntToStr(UDPDefaultPort);
BufferSize.Caption := IntToStr(UDPServer.BufferSize);
UDPServer.Active := True;
end;
procedure
TForm1.Button1Click(Sender:TObject);
begin
UDPServer.BroadcastEnabled :=true;
UDPServer.Broadcast(Edit1.Text,UDPDefaultPort1);
end;
CLIENT
-----------
const
DefaultPort = 8760;
DefaultHost = '140.100.27.8';
RECIEVETIMEOUT = 5000; // milliseconds
procedure TClient.FormCreate(Sender: TObject);
begin
UDPClient.Port := DefaultPort;
UDPClient.Binding.Port := DefaultPort;
UDPClient.Host := DefaultHost;
UDPClient.ReceiveTimeout := RECIEVETIMEOUT;
UDPClient.BroadcastEnabled := true;
end;
procedure TClient.UDPClientStatus(axSender: TObject;const axStatus:
TIdStatus; const asStatusText: String);
begin
if axStatus = hsText then
UDPMemo.Lines.Text := asStatusText;
end;
Thanks in advance