Board index » delphi » Indy scanning for an UDP server

Indy scanning for an UDP server


2006-10-31 06:04:27 PM
delphi136
Hi,
using the UDPClientServer demo (Indy 9) I am trying to implement a kind of
"scan for servers" function.
This means, currently the server runs on my local PC, however when moving
it to a real Windows server, the UDP client should be able to scan the
local network for this specific UDP server.
Is there a chance to get this running? Do I have to scan the whole (probably
unknown) IP range?
--
cu,
Michael
 
 

Re:Indy scanning for an UDP server

"Michael Fritz" <XXXX@XXXXX.COM>writes
Quote

This means, currently the server runs on my local PC, however when moving
it to a real Windows server, the UDP client should be able to scan the
local network for this specific UDP server.

Is there a chance to get this running? Do I have to scan the whole (probably
unknown) IP range?
No need to scan, as UDP supports broadcasting.
The way I did this, was to let the server listen on a specific UDP port. Whenever a client
comes alive, it broadcasts a specific message to this UDP port. The server - which could
be anywhere on the subnet - would respond to that message with a return message with
required data (depends on your needs of course). After that, communications went on using
TCP/IP.
This works equally well on local servers as on servers on the network.
Hope this helps.
...Arjan...
 

Re:Indy scanning for an UDP server

"Arjan de Haan" writes <news:4547236b$XXXX@XXXXX.COM>:
Quote
No need to scan, as UDP supports broadcasting.
The way I did this, was to let the server listen on a specific UDP port. Whenever a client
comes alive, it broadcasts a specific message to this UDP port. The server - which could
be anywhere on the subnet - would respond to that message with a return message with
required data (depends on your needs of course). After that, communications went on using
TCP/IP.
Arjan,
this means you enabled property BroadcastEnabled on client and/or on server
application?
I guess you then used sthg. like this: TIdUDPClient.Broadcast('REQUEST_IP',
8090) and receive an answer in, yes, which event receives the answer from
the server? OnStatus or TIdUDPClient.ReceiveString?
What happens if more than one UDP servers are running. How do I cover this
situation? Wait a specific time...
--
cu,
Michael
 

Re:Indy scanning for an UDP server

"Michael Fritz" <XXXX@XXXXX.COM>writes
Quote
this means you enabled property BroadcastEnabled on client
and/or on server application?
It means using the Broadcast() method on the client. It manages the
BroadcastEnabled property internally. You do not need to set it manually.
Quote
I guess you then used sthg. like this:
TIdUDPClient.Broadcast('REQUEST_IP',
8090) and receive an answer
Yes.
Quote
which event receives the answer from the server?
None, because TIdUDPClient has no reading events at all. You will have to
call one of the Receive...() methods in your own code after Broadcast()
exits. Otherwise, use TIdUDPServer instead of TIdUDPClient. It has an
OnUDPRead event for asynchronous notification of inbound data, and it has
all of the same reading/writing methods that TIdUDPClient has.
Quote
OnStatus or TIdUDPClient.ReceiveString?
ReceiveString() is not an event.
Quote
What happens if more than one UDP servers are running.
If they understand how to reply to the request, then you will receive
multiple answers. Your code has to be able to handle that. Broadasting is
a good way to detect all available servers on a subnet. You could wait for
all of the replies to arrive, build up a list of the received information,
and then present it to the user to decide what to do next.
Gambit
 

Re:Indy scanning for an UDP server

"Michael Fritz" <XXXX@XXXXX.COM>writes
Quote
this means you enabled property BroadcastEnabled on client and/or on server
application?

I guess you then used sthg. like this: TIdUDPClient.Broadcast('REQUEST_IP',
8090) and receive an answer in, yes, which event receives the answer from
the server? OnStatus or TIdUDPClient.ReceiveString?
Remy answered most if not all of your questions already (saves me diving into the sources
again ;-)).
Quote

What happens if more than one UDP servers are running. How do I cover this
situation? Wait a specific time...

For me, I didn't had the multiple servers requirement back then. I do now....;-(
Although the client broadcasted using UDP, it received the answer from the server thru
TCP/IP, so I did not have the need to listen for UDP answers on the client. The server
knows the IP address when receiving the broadcast event, and then used TCP/IP for further
communications with the client. Each message had a specific format which included some
magic words flagging the type of message. The client would react on those flags. It simply
discarded all its own communications until it had received an answer from a server - the
app _required_ a server to operate, so it _had_ to wait until a server responded anyway.
Hope this helps.
...Arjan...
 

Re:Indy scanning for an UDP server

"Arjan de Haan" writes <news:XXXX@XXXXX.COM>:
Quote
For me, I didn't had the multiple servers requirement back then. I do now....;-(
Although the client broadcasted using UDP, it received the answer from the server thru
TCP/IP, so I did not have the need to listen for UDP answers on the client. The server
knows the IP address when receiving the broadcast event, and then used TCP/IP for further
communications with the client. Each message had a specific format which included some
magic words flagging the type of message. The client would react on those flags. It simply
discarded all its own communications until it had received an answer from a server - the
app _required_ a server to operate, so it _had_ to wait until a server responded anyway.

Thanks for your reply!
--
cu,
Michael