 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Juan Rosell Guest
|
Posted: Wed Jan 28, 2004 8:22 am Post subject: A question about TUdpSocket component. |
|
|
Hi,
I´m new to Delphi and I was trying to implement a kind of distributed
application. The idea is having 3 different computers in a network running
the same application, this 3 instances of the application do share some
configuration issues which I´d like to be shared on the network. The idea
was, by using UDPSockets, to broadcast the configuration all over the
network whenever it was changed in any of the nodes. I was trying to use
TUDPSocket, but I cannot receive anything (even when I try to connect to
only one machine.)
I´ve build a couple of test applications; one of them acts as a UDP server
, binds to a port and waits for the client to send a string and then, shows
it. But the string never arrives. Here you are the code I use, maybe I´m
missing something? Any hint will be appreciated.
application one (server).
------------------------
type
TForm1 = class(TForm)
UdpSocket1: TUdpSocket;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
procedure OnReceive(Sender: TObject; Buf: pchar; var DataLen: Integer);
procedure OnConnect(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnConnect(Sender:Tobject);
begin
ShowMessage('Conectado!');
end;
procedure TForm1.OnReceive(Sender: TObject; Buf: pchar; var DataLen:
Integer);
begin
ShowMessage(buf);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
UdpSocket1.LocalHost:='juan';
UdpSocket1.LocalPort:='3000';
UdpSocket1.OnReceive:= OnReceive;
UdpSocket1.OnConnect:=OnConnect;
UdpSocket1.Open;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UdpSocket1.Close;
end;
end.
application two (client).
----------------------
type
TForm1 = class(TForm)
UdpSocket1: TUdpSocket;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
str:string;
begin
UdpSocket1.RemoteHost:='juan';
UdpSocket1.RemotePort:='3000';
str:='hola';
if UdpSocket1.Connect then
begin
{
just to see where it´s connected.
}
ShowMessage('Remote host='+UdpSocket1.RemoteHost + ' remote
port='+UdpSocket1.RemotePort);
UdpSocket1.Sendln(str);
end;
end;
end.
I read also in the news that someone was missing the "bind" method in
TUDPSockets, well I´m missing it to, maybe the local port is bound as soon
as it´s associated?
Regards,
Juan
|
|
| Back to top |
|
 |
CheshireCat Guest
|
Posted: Fri Jan 30, 2004 1:48 pm Post subject: Re: A question about TUdpSocket component. |
|
|
Is this borlands udp sockets? If so then don't use them - they were buggy
and didn't work when I last used them. Use Indys UDP server sockets instead.
Also, you don't connect sockets with UDP. It's a discrete datagram protocol.
Look at the broadcast method too
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.572 / Virus Database: 362 - Release Date: 27/01/2004
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|