udp 多线程客户端和单线程服务器端

该博客介绍了如何实现一个UDP多线程客户端,它能读取本地文件内容并发送到服务器。服务器端接收到信息后打印,并回传当前时间。客户端再接收到服务器消息并进行打印,详细阐述了整个通信过程。
摘要由CSDN通过智能技术生成

具体功能: 客户端读取本地的文件,将内容发给服务器,服务器打印接收到的信息并返回当前服务器的时间,客户端接收到服务器发的消息,打印


客户端:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <netdb.h>
#include <fcntl.h>

#define MAX_THREAD 26
#define BUFFER_SIZE 1024

char *src_path = "/home/test";

struct MYPARAM
{
    char *server_ip;
    char *server_port;
};

//读取本地文件
void read_file(char buffer[], char* src)
{
    char buffer1[1024];
    int read_size;
    int src_fd;
    //打开本地文件 
    if((src_fd = open(src, O_RDONLY)) < 0)
    {
        perror("Open /home/test  failed:");
        exit(1);
    }
    //读取本地文件 
    if((read_size = read(src_fd, buffer, sizeof(b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值