Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12606 Discussions

nios udp connection, can send but not receieve

Altera_Forum
Honored Contributor II
1,076 Views

hi, all. almost crazy about the udp connection based on development board, my code as follows, it can send message to the pc and pc can receieve the message without any problem, in my code, i run the pc as server and board as client. when pc receieve message, it will send it back to the board, however, my board never receieve it although i see the lan port receieveing flash, please suggest the reason 

 

 

nios side 

 

static void udp_test_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, 

struct ip_addr *addr, u16_t port) 

err_t err; 

err=udp_connect(pcb,addr,port); 

if (err!= ERR_OK) 

printf("\n ERROR connection in receieving %d \n",err); 

udp_packets++; 

udp_send(pcb,p); 

 

pbuf_free(p); 

udp_remove(pcb); 

 

 

return; 

}  

 

void main() 

int i; 

struct udp_pcb *pcb; 

struct pbuf* pbuflfsr; 

struct ip_addr udpDestIpAddr,udpLocalIpAddr; 

pbuf_layer layer=PBUF_TRANSPORT; 

pbuf_flag flag=PBUF_RAM; 

u16_t size=1024; 

 

IP4_ADDR(&udpDestIpAddr, 10, 0, 0, 52); 

IP4_ADDR(&udpLocalIpAddr, 10, 0, 0, 51); 

 

printf("udp_init\n"); 

 

udp_packets = 0; 

 

 

while(1) 

pcb = udp_new(); 

 

 

udp_connect(pcb, &udpDestIpAddr,10); 

 

pbuflfsr = pbuf_alloc(layer,size,flag);  

for(i=0;i<=size-1;i++) //data 

((u8_t *)(pbuflfsr->payload))[i] = 0x11; 

 

 

udp_sendto(pcb, pbuflfsr, &udpDestIpAddr, 10); 

 

usleep(500); 

 

 

udp_recv(pcb,udp_test_recv,NULL); 

 

pbuf_free(pbuflfsr); 

udp_remove(pcb); 

 

}  

}  

 

 

pc side: 

 

SOCKET socket1; 

 

struct sockaddr_in local; 

struct sockaddr_in from; 

int fromlen =sizeof(from); 

local.sin_family=AF_INET; 

local.sin_port=htons(10);  

local.sin_addr.s_addr=INADDR_ANY;  

 

 

socket1=socket(AF_INET,SOCK_DGRAM,0); 

bind(socket1,(struct sockaddr*)&local,sizeof local); 

while (1) 

char buffer[1024]="\0"; 

printf("waiting for message from others-------------\n"); 

if (recvfrom(socket1,buffer,sizeof buffer,0,(struct sockaddr*)&from,&fromlen)!=SOCKET_ERROR) 

sendto(socket1,buffer,sizeof buffer,0,(struct sockaddr*)&from,fromlen); 

Sleep(5); 

closesocket(socket1);
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
350 Views

Please read this thread (http://forum.niosforum.com/forum/index.php?showtopic=2803&hl=udp) as it&#39;s answers exactly what you&#39;re trying to do. 

 

If you have specific questions, following a careful inspection of the above thread, I&#39;ll be happy to answer them, though I&#39;d prefer that you try to get the code that I posted there to run.....first. 

 

Also, since you&#39;re going down the path of using the raw API, you need to be using the stand alone version of lwip (http://forum.niosforum.com/forum/index.php?showtopic=949). 

 

Cheers, 

 

- slacker
0 Kudos
Reply