Hello,
I need to send a UDP package with this function( netUDP_Send )
https://www.keil.com/pack/doc/mw/Network/html/group__udp__user__api.html#ga7a82db98b82300e5fd03ce1b7afb6cba
But I don't have remote IP and Port number. I have added a new variable to get remote IP and Port number but it shows me an error.
NET_ADDR4 addrUDP;uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) { addrUDP=addr; return 0;}
How can I send a UDP package?
Hello, Here is my program which works fine for broadcast.
int main (void){ netInitialize (); Eth(); while(1){ Sendd(); osDelay(100); } } NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 255, 255 }; uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) { return 0; } void Eth(){ uint8_t mac_addr [NET_ADDR_ETH_LEN]; uint8_t ip4_addr [NET_ADDR_IP4_LEN]; socket = netUDP_GetSocket(udp_cb_func); if (socket >= 0) { netUDP_Open(socket, 2050); } void Sendd(void){ sendbuf = netUDP_GetBuffer (2); sendbuf[0]=65;sendbuf[0]=66; State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, sendbuf,2); }
I received transmitted data in my PC. However, by specifying the remote IP(NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 100, 20 };) it doesn't work even it doesn't respond to ping command. I have added "netARP_CacheIP " function based on "http://www.keil.com/pack/doc/mw/Network/html/group__udp__user__api.html?_ga=2.246941447.2042184398.1570359907-552607041.1563512165" but it only helps me to ping the device properly. but it still doesn't send anything. Here is my code
int main (void){ netInitialize (); Eth(); while(1){ Sendd(); osDelay(100); } } NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 100, 20 }; uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) { return 0; } void Eth(){ uint8_t mac_addr [NET_ADDR_ETH_LEN]; uint8_t ip4_addr [NET_ADDR_IP4_LEN]; netIP_aton ("192.168.100.100", NET_ADDR_IP4, ip4_addr); while (netARP_GetMAC (NET_IF_CLASS_ETH | 0, ip4_addr, mac_addr) != netOK) { netARP_CacheIP (NET_IF_CLASS_ETH | 0, ip4_addr, netARP_CacheTemporaryIP); osDelay (1000); } socket = netUDP_GetSocket(udp_cb_func); if (socket >= 0) { netUDP_Open(socket, 2050); } void Sendd(void){ sendbuf = netUDP_GetBuffer (2); sendbuf[0]=65;sendbuf[0]=66; State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, sendbuf,2); }
My computer address IP is 192.168.100.50 and both subnet mask is 255.255.0.0 . Ping shows me that "192.168.100.100" is available on my network but it doesn't send anything to the remote IP ( after setting broadcast IP 192.168.255.255 and removing
netIP_aton ("192.168.100.100", NET_ADDR_IP4, ip4_addr); while (netARP_GetMAC (NET_IF_CLASS_ETH | 0, ip4_addr, mac_addr) != netOK) { netARP_CacheIP (NET_IF_CLASS_ETH | 0, ip4_addr, netARP_CacheTemporaryIP); osDelay (1000); }
it sends a broadcast and complete message to my PC. what is my mistake?