1

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;
TLama
  • 75,147
  • 17
  • 214
  • 392
Sorena
  • 17
  • 4

1 Answers1

1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • after i shift it to the end and also disabled Antivirus and windows firewall , I could't receive UDP frame in my software again, when I check "netstat -e" or "wireshark" I can see received the udp frame, the netstat -e show the computer didn't receive "unknown protocols frames " but received "discards frames", – Sorena Feb 25 '15 at 02:28
  • If frames are being discarded, then their destination does not match any active socket. You might want to use netstat to also verify that your udp server IP/port is actually open and in a listening state. – Remy Lebeau Feb 25 '15 at 06:15
  • I've implemented my hardware to reply only to ARP and ICMP and make and send UDP frame, – Sorena Feb 25 '15 at 08:42
  • The only other thing I can think of is if the destination MAC on the UDP packets (`00:1e:68:4d:b7:b0`) does not match the MAC on the NIC that has IP `192.168.1.100`. Did you check that yet? You can use `ipconfig /all` for that. – Remy Lebeau Feb 25 '15 at 17:41
  • yes that's match,i can transfer udp packet between two pc, but i couldn't do that between a hardware and pc, i don't know what's the problem, maybe hardware should to reply to some packet that send by pc first, and then the connection will be established, – Sorena Feb 26 '15 at 00:36
  • UDP is connection-less, there is no packet that the PC should send to the hardware to establish a connection. If the code works fine between two PCs, then the problem has to be in your hardware. Clearly it is missing/malforming something, but there is no way to diagnose that from the limited information you have provided. So this is probably not a problem for StackOverflow anymore, as it is not a coding issue (other than the `Bindings` bug I already pointed out to you). There are other areas of the StackExchange community that are better suited to networking and engineering issues. – Remy Lebeau Feb 26 '15 at 02:09
  • I have a question , if a pc connect to the network in the first the pc start to reply to some packet that receive from network (for example arp) and initialize itself and then it will be ready to communicate in the network, or no it's possible to send only UDP packet without any reply to network, – Sorena Feb 26 '15 at 05:03
  • If a PC does not have a static IP address, it can obtain an IP from the network's DHCP server. But once it has an IP, it can start receiving packets destined for that IP. – Remy Lebeau Feb 26 '15 at 07:30
  • I found the problem after i check my hardware's udp packet with another same udp packet (same size), the problem was about the size of eth packet that my hardware fill it on the udp packet, now i can get udpread event (interrupt) in my software, i don't know why this error is not indicated by wireshark ,maybe first it need to init in the wireshark's preferences, – Sorena Feb 26 '15 at 07:50