RTC Forums

Subscription => Support => Topic started by: ClementDoss on May 31, 2015, 10:10:42 PM



Title: UDPClient broadcast
Post by: ClementDoss on May 31, 2015, 10:10:42 PM
Hi,

I'm having some troubles setting up a Multicast Client UDP using TRtcUdpClient.
I managed to make the project work with TidUDPClient, but I must use a non-blocking solution for this project.

For this sample, the client must request the server IP address.
The rtc code is :

Code:
  // Client side Setup
  FUDPClient := TRtcUdpClient.New;
  FUDPPort := 16283;
  FUDPClient.UdpMultiCast := True;
  FUDPClient.MultiThreaded := True;
  FUDPClient.UdpMultiCastMaxHops := 1;
  FUDPClient.ServerAddr := GetBroadcastIP; // returns '192.168.0.255'
  FUDPClient.ServerPort := inttostr(FUDPPort);


  // Call
  if FUDPClient.isConnected then FUDPClient.Disconnect;
  FUDPClient.Connect;
  try
    FUDPClient.Write('? <HOST,PORT>');
    Sleep(1000);
  finally
    FUDPClient.Disconnect;
  end;




The Indy code is
Code:
var
  lAns : String;
  lUDPClient  : TidUDPClient;
begin
   lUDPClient  := TidUDPClient.Create;
   try
     lUDPClient.Port := 16283;
     if lUDPClient.Connected then lUDPClient.Disconnect;
     try
       lUDPClient.Broadcast('? <HOST,PORT>', lUDPClient.Port, GetBroadcastIP );
       lAns := lUDPClient.ReceiveString(1000);
     finally
       Result := length(lAns)<>0;
       lUDPClient.Disconnect;
     end;
   finally
     lUDPClient.Free;
   end;

It's the same rtcUDPServer for both example. The indy code triggers correctly the server side events.
I'm unable to make rtcUDPClient do the same.
( I also tried using setting the serveraddress to '255.255.255.255'. Indy code works, rtc no joy.. )

What am I missing?

Best regards,
Clément


Title: Re: UDPClient broadcast
Post by: D.Tkalcec (RTC) on June 01, 2015, 12:21:02 AM
Connect and Write methods when using UDP with RTC are asynchronous (message driven and require a message loop), which means that you can NOT simply call Connect, Write something, use a blocking Sleep and then Disconnect. Nothing will go out that way. You need to call Connect, wait for the OnConnect event and use Write from there. Calling Disconnect on the UDP connection with RTC will immediately stop the connection from working and clear connections sending and receiving buffers.

Check the UdpMessages Project in the Demos/RAW_UDP folder.

Best Regards,
Danijel Tkalcec


Title: Re: UDPClient broadcast
Post by: ClementDoss on June 01, 2015, 08:15:39 PM
Hi Danijel,

I still thinking "blocking". That's the issue  ;D

After re-reading the Demos/RAW_UDP project, I managed to make my project works as I need.
So much better!

Thanks for answering with such details.

Clément