{
Int addr_length;
Int data_lenght;
int ret;
Struct sockaddr_in source_add;
Struct sockaddr_in local_addr;
Server_fd=socket (AF_INET, SOCK_DGRAM, 0);
If (server_fd==1)
Printf (" server_fd create failed \ n ");
Bzero (& amp; Local_addr, sizeof (local_addr));
Local_addr. Sin_family=AF_INET;
Local_addr. Sin_port=htons (LOCAL_PORT);///3341
Local_addr. Sin_addr. S_addr=htonl (INADDR_ANY);
Ret=bind (server_fd, (struct sockaddr *) & amp; Local_addr, sizeof (local_addr));
If (ret!=1)
Printf (" bind 3341 sucess \ n ");
While (1)
{
Memset (databuffer, 0, BUFF_LEN);
Data_lenght=recvfrom (server_fd, databuffer, sizeof (databuffer), 0, \
(struct sockaddr *) & amp; Source_add, & amp; Addr_length);
If (data_lenght==1)
{
Printf (" data recieved fail \ n ");
return;
}
Printf (" data recieved sucess \ n ");
}
}
CodePudding user response:
Ask an expert to solve, don't know is code problem or other reasons, using a computer can't Linux boards don't know what the reason, Linux board is automatically assigned IPCodePudding user response:
To be sure the two sides is within a local area network (LAN)CodePudding user response:
Computer firewall has all closed downCodePudding user response:
First the udp protocol and ping (ICMP protocol) no correlation, so can't has nothing to do with the udp program.PC can't Linux, Linux can ping PC? Linux firewall is turned off (iptables -a INPUT -j ACCEPT try)?