I'm trying to make the communication between applications where one of them transmits a certain message and the others only receive, I do not know the IP address of the ones they will receive and they will not even be there to receive the message, multicast on the network.
I'm using Ararat Synapse with the TUDPBlockSocket
class and found the following example on the component's website ...
Receiving the message
procedure TForm1.btnReceberClick(Sender: TObject);
var
rcvsock:TUDPBlockSocket;
buf:string;
begin
rcvsock:=TUDPBlockSocket.Create;
try
rcvsock.createsocket;
rcvsock.Bind('0.0.0.0','22401');
rcvsock.AddMulticast('234.5.6.7');
buf:=rcvsock.RecvPacket(60000);
showmessage(buf);
finally
rcvsock.free;
end;
end;
Sending the message
procedure TForm1.btnEnviarClick(Sender: TObject);
var
sndsock:TUDPBlockSocket;
begin
sndsock:=TUDPBlockSocket.Create;
try
sndsock.createsocket;
sndsock.Bind('0.0.0.0','0');
sndsock.MulticastTTL := 1;
sndsock.connect('234.5.6.7','22401');
sndsock.SendString('Ahoy!'+CRLF);
finally
sndsock.free;
end;
end;
This works fine if you open only 2 instances of the application and at first click the btnReceber
button and the second click the btnEnviar
button. However I open 3 instances, one sending and the other two receiving only one receives and the other stands there waiting for the 60000 milliseconds. The only two-instance test works only if both are running on the same machine, and I've already checked that my router was enabled with IGMP to allow multicast , but it still did not work over the network.
I'm using Delphi XE and did testing on Windows XP on a VM with Virtual Box and also on a Windows 7 computer.