基于UDP------服务器端:
1.创建一个socket,用函数socket()
2.绑定IP地址、端口信息等到socket上,用函数bind()
3.循环接收数据,用函数recvfrom()
4.关闭网络连接
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define SERVER_PORT 8888
#define MAX_MSG_SIZE 1024
void udps_respon(int sockfd)
{
struct sockaddr_in addr;
int addrlen,n;
char msg[MAX_MSG_SIZE];
while(1)
{ /* 从网络上读,并写到网络上 */
bzero(msg,sizeof(msg)); // 初始化,清零
addrlen = sizeof(struct sockaddr);
n=recvfrom(sockfd,msg,MAX_MSG_SIZE,0,(struct sockaddr*)&addr,&addrlen); // 从客户端接收消息
msg[n]=0;
/* 显示服务端已经收到了信息 */
fpr