We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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?
Parisa Mohamadi said:But I don't have remote IP and Port number
Obviously, those are essential - you can't send a packet if you don't know where it's going!
Parisa Mohamadi said:it shows me an error
What, exactly, "shows you an error" ?
And what error, exactly, does "it" show ?
I really appreciate your response.
I need to set my device IP Address to 192.168.1.100 and listen to 2050 port. Here is my code:
int main (void){ netInitialize (); Eth(); while(1){ Sendd(); osDelay(100); } } NET_ADDR4 addrUDP={ NET_ADDR_IP4, 5022, 192, 168, 1, 10 }; uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) { //addrUDP=addr; return 0; } void Eth(){ uint8_t mac_addr [NET_ADDR_ETH_LEN]; uint8_t ip4_addr [NET_ADDR_IP4_LEN]; netIP_aton ("192.168.1.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 (Ether.DataSize); State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, sendbuf,Ether.DataSize); if(State!=netOK){ netUDP_Close(socket); socket = netUDP_GetSocket(udp_cb_func); if (socket >= 0) { netUDP_Open(socket, 2050); netUDP_SetOption (socket, netUDP_OptionTTL, 2); } } }
After programming, I can ping my device( 192.168.1.100 is alive). But I need to do two different strategies:
1)Obtaining remote IP address without inserting in my code (192.168.1.10)
2)Send a UDP package.
I have set my device to 192.168.1.100 and it is activated in my network( it responds to ping command). But I cant received anything. Here is my code
int main (void){ netInitialize (); Eth(); while(1){ Sendd(); osDelay(100); } } NET_ADDR4 addrUDP={ NET_ADDR_IP4, 5022, 192, 168, 1, 10 }; uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) { //addrUDP=addr; return 0; } void Eth(){ uint8_t mac_addr [NET_ADDR_ETH_LEN]; uint8_t ip4_addr [NET_ADDR_IP4_LEN]; netIP_aton ("192.168.1.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){ sprintf(buf,"H%d",1); sendbuf = netUDP_GetBuffer (2); State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, buf,2); if(State!=netOK){ netUDP_Close(socket); socket = netUDP_GetSocket(udp_cb_func); if (socket >= 0) { netUDP_Open(socket, 2050); netUDP_SetOption (socket, netUDP_OptionTTL, 2); } } }
I need to do two work.
1) Obtaining remote IP address without inserting into my code (192.168.1.10)
2) Sending a simple UDP package.
So what's the error, that you're trying to set an array to a pointer? Perhaps you should be copying the content? Perhaps the pointer is dynamic/temporal in nature?