RTC Forums
November 24, 2024, 03:29:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: UDPClient broadcast  (Read 4484 times)
ClementDoss
RTC License
***
Posts: 36


« 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
ClementDoss
RTC License
***
Posts: 36


« Reply #2 on: June 01, 2015, 08:15:39 PM »

Hi Danijel,

I still thinking "blocking". That's the issue  Grin

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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.