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

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Locating RTC server in the LAN  (Read 3972 times)
mastinfo
RTC License
***
Posts: 29


« on: October 17, 2014, 04:24:11 PM »

Hello,

I'm wondering if there's the possibility for an RTC client to get the list of all RTC servers (or all HTTP servers)  running in the LAN.

I have done something but it's a bit slow.
First i get the list of all devices connected to the LAN (this part is not very slow, taks only few seconds)
Then, for each device, (i have the name) i try to execute a remote function. This part is slow: it takes many seconds for each device.

thanks in advance for any suggestion.

Roberto
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: October 17, 2014, 04:32:52 PM »

If all your Servers are inside LAN and all your Clients are running on Windows, you can use UDP broadcasting to find the Servers. Clients who want to find all the running Servers, would use a TRtcUDPClient component with a Broadcast address to send out an UDP packet and wait for a response. And all of your Servers who want to be found would use a TRtcUDPServer component to listen for UDP packets on that same UDP Port and respond with their IP address and Port when they received the UDP packet from a Client.

To register UDP components on the Delphi component palette, you will need to install the rtcSDK_RAW package in addition to the rtcSDK package. For an example on using UDP components, check the UdpMessages Project inside the Demos/Raw_UDP folder.

Best Regards,
Danijel Tkalcec
Logged
mastinfo
RTC License
***
Posts: 29


« Reply #2 on: October 17, 2014, 05:40:07 PM »

Thanks i'll try it.

Roberto
Logged
mastinfo
RTC License
***
Posts: 29


« Reply #3 on: October 20, 2014, 02:23:18 PM »

hello  Cheesy

I'm working on this thing.

I'm not experienced with UDP anyway i have wrote some code that seems to work.
I do the following:

1) Setup the udpclient with the following settings;
  UDPMULTICAST=true
  UDPMULTICASTMAXHOPS=255
  MULTITHREADED=false;
  SERVERADDR=192.168.2.255
  SERVERPORT=81;

2) Open the udpclient component
3) Write a query string ('QUERY SERVER')
4) In the server ondatareceived i check if the text received is QUERY SERVER
5) If the data received is correct i write back the IP of the pc (i tought that the property LocalAddr returned it but i see it's empty, so i have used another function)
6) In the ondatareceived event of the udpclient i add the ip address received to a global stringlist

I use a code similar to the following to begin the query in the client side.
I see it works but i'k not sure if i'm doing it in the right way. Sincerly i expected it didn't work because
when i do the first write to query servers (Write('QUERY_SERVER')Wink the execution should immediately continue and the stringlist should be then empty. I'm surprised  to see that the stringlist is populated with the up address of the servers. Does it mean that the WRITE method wait for all the servers have replyed ?



    Fserver_list:=Tstringlist.Create;
    try
      Write('QUERY SERVER');
     
      // Now i have the stringlist populated with the IP address of the RTC servers found in the LAN

      for idx := 0 to Fserver_list.count-1 do
      begin
         showmessage(Fserver_list[idx]);
      end;
    finally
      Fserver_list.Free;
    end;
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 on: October 20, 2014, 03:57:20 PM »

When using UDP, the Write method is executed immediately, but the result will be received asynchronously. When using Broadcasting or Multicasting, the message will be transmitted to all possible recipients and all of them will most respond more-or-less at the same time, which is why your whole IP Address list will be populated after a single call. But I'd still put some wait period to make sure all the Server have enough time to respond. For example, you could use the UDP Client component with MultiThreaded=TRUE and use a Sleep(500) after calling Write, to give Servers some time to respond.

PS. You can run your Client in Debug mode in Delphi and put breakpoints where the list is being populated to see what exactly happens.

Best Regards,
Danijel Tkalcec
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 17 queries.