当前位置: 技术问答>linux和unix
udp socket 协议问题,大家帮我找找原因,出现的错误是 recv: Bad address
来源: 互联网 发布时间:2017-02-08
本文导语: 运行结果: [root@heiying udp]# ./udp_client recv: Bad address [root@heiying udp]# [root@heiying udp]# ./udp_server receive from client is A 服务端 udp_server #include #include #include #include #include #include #include int main(int argc,c...
运行结果:
[root@heiying udp]# ./udp_client
recv: Bad address
[root@heiying udp]#
[root@heiying udp]# ./udp_server
receive from client is A
服务端 udp_server
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int server_sockfd, client_sockfd;
int server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;
int i,byte;
char char_recv,char_send;
server_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
server_address.sin_port = 9734;
server_len = sizeof(server_address);
bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
client_len=sizeof(client_address);
for(i=0,char_send='1';i
[root@heiying udp]# ./udp_client
recv: Bad address
[root@heiying udp]#
[root@heiying udp]# ./udp_server
receive from client is A
服务端 udp_server
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int server_sockfd, client_sockfd;
int server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;
int i,byte;
char char_recv,char_send;
server_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
server_address.sin_port = 9734;
server_len = sizeof(server_address);
bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
client_len=sizeof(client_address);
for(i=0,char_send='1';i