一、建立头文件
#ifndef __HEAD_H__ //防止头文件被重复定义
#define __HEAD_H__ ////防止头文件被重复定义#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <poll.h>
#include <semaphore.h>
#include <pthread.h>#endif ////防止头文件被重复定义
(头文件所使用的函数不一定都用到,方便下次写其他代码,所以大部分都写在上面)
二、客户端
思路: socket------>sendto----->pthread(建立两个线程,一个负责发送,一个负责接收)------>close
使用自己的IP号
#include "head.h"
struct sockaddr_in ser;
int init_udp_cli(char *ip ,unsigned short po

本文展示了如何使用C语言通过UDP协议建立客户端和服务端的通信。客户端创建两个线程分别处理发送和接收数据,服务端同样使用线程进行发送和接收。头文件包含了多种系统调用,用于网络通信和多线程操作。
最低0.47元/天 解锁文章
980

被折叠的 条评论
为什么被折叠?



