Sorena
Sorena

Reputation: 17

receiving UDP data in PC that send by hardware,

I've developed a hardware (client,src ip 192.168.01.200 :9652, des ip 192.168.01.100 :9652) that reply ARP and ICMP request from pc and send UDP frame, i can check the UDP frame , ARP and icmp reply in wireshark and all of these frames are ok but i can't receive anything in my software,

in pc side (server) i set up ip address 192.168.01.100 and i wrote delphi code for receiving udp frame by using indy10 , and then i check On_udp_read event for receiving data but this event never occur,

sever (pc):

  udpserver.Active := True;
  binding:=udpserver.bindings.add;
  binding.IP:= '192.168.01.100'; // my computer IP
  binding.Port:=9652;

Upvotes: 1

Views: 1167

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596602

You need to set up the Bindings collection before you activate the server, not after:

//udpserver.Active := True;
binding := udpserver.Bindings.Add;
binding.IP := '192.168.01.100';
binding.Port := 9652;
udpserver.Active := True; // <-- move down here

If the Bindings collection is empty when you activate the server, it will create a default item that is bound to IP 0.0.0.0 (IPv4) or ::1 (IPv6) on the TIdUDPServer.DefaultPort, which is 0 by default. So you would end up binding to a random OS-assigned port, unless you set the DefaultPort beforehand, eg:

udpserver.DefaultPort := 9652;
udpserver.Active := True;

Upvotes: 1

Related Questions