套接字通信(C/C++ 多线程)----基于线程池的并发服务器

news2024/9/25 3:29:05

(一)大家可以看我写的这三篇,了解一下: 

基于linux下的高并发服务器开发(第四章)- 多线程实现并发服务器_呵呵哒( ̄▽ ̄)"的博客-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/132026417?spm=1001.2014.3001.5501

手写线程池 - C语言版 - 笔记总结_呵呵哒( ̄▽ ̄)"的博客-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/131926834?spm=1001.2014.3001.5501

基于多线程实现服务器并发_呵呵哒( ̄▽ ̄)"的博客-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/132047357?spm=1001.2014.3001.5501

(二)在套接字服务器端使用线程池的思路:

        两类任务需要处理:第一类任务就是和客户端建立连接,第二类任务就是和客户端建立连接之后进行数据通信,所以可以把与客户端建立连接抽象出一个函数,和客户端进行通信抽象一个函数。

        那么在通信的过程中,线程有多少个是由谁来管理呢?其实是由管理者线程来维护的。综上所述,如果我们使用了线程池,不管是和客户端建立连接,还是和客户端进行通信,其实都是由工作的线程来完成的。除此之外,工作的线程和管理者线程其实他们都是子线程。如果他们都是子线程,那么程序中的这个主线程干什么事情呢?其实在程序里的主线程,它只需要把监听的套接字创建出来,然后进行绑定,设置监听,接着把这个线程池对象创建出来。然后把这个接受客户端连接的任务放到线程池里边,主线程的使命其实就算是完成了。这个时候我们就可以让主线程退出了。【pthread_exit(NULL);】如果单纯的让主线程退出,也不会影响子线程的执行。这个子线程就是线程池里边所有的线程,基于这些线程池里边运行的线程就可以和客户端建立连接,并且和客户端进行通信。

(三)使用多线程和使用线程池在逻辑上是有一些区别的:

如果直接编写多线程程序,需要在这个主线程里边去做一个accept操作,在这个子线程里边去做通信。但是如果使用了线程池里边的主线程,这个主线程主要负责把线程池创建出来,在线程池里边的n个子线程就负责和客户端建立连接,并且和建立连接成功的客户端进行通信。这些都是由线程池里边的这n个工作的子线程来完成的。线程池里边这个子线程的创建和销毁,都是由线程池里边的这个管理者线程来维护的。这一点是手写线程池和使用线程池思路上有一些区别的地方。

(1)主线程需要完成的任务:

1.创建监听的套接字 lfd

int lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd == -1) {
	perror("socket");
	exit(-1);
}

2.绑定本地的IP port

// 2.绑定本地的IP port
struct sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);//主机字节序转换成网络字节序
saddr.sin_addr.s_addr = INADDR_ANY;// 0 = 0.0.0.0 对于0来说,大端和小端是没有区别的的,因此不需要转换

int ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
	perror("bind");
	exit(-1);
}

3.设置监听

ret = listen(lfd,128);
if(ret == -1) {
	perror("listen");
	exit(-1);
}

4.创建线程池

// 创建线程池 
ThreadPool* pool =threadPoolCreate(3,8,100);
PoolInfo* info = (PoolInfo*)malloc(sizeof(PoolInfo));
info->pool = pool;
info->fd = lfd;

5.给线程池添加任务 

threadPoolAdd(pool,acceptConn,info);

         给线程池添加任务 (让线程池里边的线程去检测有没有新的客户端连接)因此把这个任务需要的信息放到了一块堆内存里面 :PoolInfo* info = (PoolInfo*)malloc(sizeof(PoolInfo));这个堆内存什么时候被释放呢?当这个acceptConn函数执行完毕之后,它就会把info这块内存释放掉了。主线程完成添加任务操作之后,我们就让主线程退出了。

6.主线程退出

pthread_exit(NULL);

         到此为止,主线程的使命已经结束,我们可以让主线程退出,剩下的所有任务都是由子线程来做的。(这个子线程就是线程池里边的线程)通过pthread_exit(NULL);调用,它只会让当前的线程退出,并不会影响其他线程的运行。也就是说主线程退出了,它并不会影响线程池里边所有的线程的运行。

        咱们写的这个线程池里边并没有对线程进行销毁操作,因为我们线程池里边的这些任务函数他们执行的是一个死循环,也就意味着你不认为的去终止这些线程池里边的线程执行的任务,是不能执行完毕的,是停不了的。因此在这里就不做销毁了。在正常的项目里的任务肯定是由终止的时刻的,当任务终止了之后,就需要把相关的资源全部释放掉。那么这种关于子线程的任务函数也就执行完毕了。

(2)子线程需要完成的任务:

先准备相关结构体

// 信息结构体
typedef struct SockInfo {
    struct sockaddr_in addr;
    int fd;
}SockInfo;

typedef struct PoolInfo{
    ThreadPool* pool;
    int fd;
}PoolInfo;

1.与客户端建立连接

void acceptConn(void* arg) {
    PoolInfo* poolInfo = (PoolInfo*)arg;
    // 4.阻塞并等待客户端的连接
    int addrlen = sizeof(struct sockaddr_in);
    while (1)
    {
        SockInfo* pinfo;
        pinfo = (SockInfo*)malloc(sizeof(SockInfo));
        pinfo->fd = accept(poolInfo->fd,(struct sockaddr*)&pinfo->addr,&addrlen);
        if(pinfo->fd == -1) {
            perror("accept");
            break;
        }
        // 添加通信的任务
        threadPoolAdd(poolInfo->pool,working,pinfo);
    }
    // 把用于监听的文件描述符给关掉
    close(poolInfo->fd);
}

2.和客户端进行通信

void working(void* arg) {
    struct SockInfo* pinfo = (struct SockInfo*)arg;
    // 连接建立成功,打印客户端的IP和端口信息
    char ip[32];
    
    printf("客户端的IP: %s,端口: %d\n",
            inet_ntop(AF_INET,&pinfo->addr.sin_addr.s_addr,ip,sizeof(ip)),
            ntohs(pinfo->addr.sin_port));
    
    // 5.通信
    while(1) {
        // 接收数据
        char buff[1024];
        int len = recv(pinfo->fd,buff,sizeof(buff),0);
        if(len > 0) {
            printf("client say: %s\n",buff);
            send(pinfo->fd,buff,len,0);
        }else if(len == 0) {
            printf("客户端已经断开了连接...\n");
            break;
        }else{
            perror("recv");
            break;
        }
    }
    
    // 关掉文件描述符
    close(pinfo->fd);
    // 当任务执行完成之后,会在线程池里边销毁pinfo指向的内存
}

完整代码:

server.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "threadpool.h"

// 信息结构体
typedef struct SockInfo {
    struct sockaddr_in addr;
    int fd;
}SockInfo;

typedef struct PoolInfo{
    ThreadPool* pool;
    int fd;
}PoolInfo;


void working(void* arg);
void acceptConn(void* arg);

int main() {
    // 1.创建监听的套接字 lfd
    int lfd = socket(AF_INET,SOCK_STREAM,0);
    if(lfd == -1) {
        perror("socket");
        exit(-1);
    }
    // 2.绑定本地的IP port
    struct sockaddr_in saddr;
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(9999);//主机字节序转换成网络字节序
    saddr.sin_addr.s_addr = INADDR_ANY;// 0 = 0.0.0.0 对于0来说,大端和小端是没有区别的的,因此不需要转换

    int ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
    if(ret == -1) {
        perror("bind");
        exit(-1);
    }

    // 3.设置监听
    ret = listen(lfd,128);
    if(ret == -1) {
        perror("listen");
        exit(-1);
    }

    // 创建线程池 
    ThreadPool* pool =threadPoolCreate(3,8,100);
    PoolInfo* info = (PoolInfo*)malloc(sizeof(PoolInfo));
    info->pool = pool;
    info->fd = lfd;
    threadPoolAdd(pool,acceptConn,info);
    pthread_exit(NULL);
    return 0;
}

void acceptConn(void* arg) {
    PoolInfo* poolInfo = (PoolInfo*)arg;
    // 4.阻塞并等待客户端的连接
    int addrlen = sizeof(struct sockaddr_in);
    while (1)
    {
        SockInfo* pinfo;
        pinfo = (SockInfo*)malloc(sizeof(SockInfo));
        pinfo->fd = accept(poolInfo->fd,(struct sockaddr*)&pinfo->addr,&addrlen);
        if(pinfo->fd == -1) {
            perror("accept");
            break;
        }
        // 添加通信的任务
        threadPoolAdd(poolInfo->pool,working,pinfo);
    }
    // 把用于监听的文件描述符给关掉
    close(poolInfo->fd);
}

void working(void* arg) {
    struct SockInfo* pinfo = (struct SockInfo*)arg;
    // 连接建立成功,打印客户端的IP和端口信息
    char ip[32];
    
    printf("客户端的IP: %s,端口: %d\n",
            inet_ntop(AF_INET,&pinfo->addr.sin_addr.s_addr,ip,sizeof(ip)),
            ntohs(pinfo->addr.sin_port));
    
    // 5.通信
    while(1) {
        // 接收数据
        char buff[1024];
        int len = recv(pinfo->fd,buff,sizeof(buff),0);
        if(len > 0) {
            printf("client say: %s\n",buff);
            send(pinfo->fd,buff,len,0);
        }else if(len == 0) {
            printf("客户端已经断开了连接...\n");
            break;
        }else{
            perror("recv");
            break;
        }
    }
    
    // 关掉文件描述符
    close(pinfo->fd);
    // 当任务执行完成之后,会在线程池里边销毁pinfo指向的内存
}

client.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>

int main() {
    // 1.创建套接字
    int fd = socket(AF_INET,SOCK_STREAM,0);
    if(fd == -1) {
        perror("socket");
        return -1;
    }

    // 2.连接服务器IP port
    struct sockaddr_in saddr;
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(9999);
    inet_pton(AF_INET,"192.168.88.129",&saddr.sin_addr.s_addr);
    int ret = connect(fd,(struct sockaddr*)&saddr,sizeof(saddr));
    if(ret == -1) {
        perror("connect");
        return -1;
    }

    int number = 0;
    // 3.通信
    while(1) {
        // 发送数据
        char buff[1024];
        sprintf(buff,"你好,呵呵哒,%d...\n",number++);
        send(fd,buff,strlen(buff) + 1,0);

        //接收数据
        memset(buff,0,sizeof(buff));
        int len = recv(fd,buff,sizeof(buff),0);
        if(len > 0) {
            printf("server say: %s\n",buff);
        }else if(len == 0) {
            printf("服务器已经断开了连接...\n");
            break;
        }else{
            perror("recv");
        }
        sleep(1);
    }
    // 关闭文件描述符
    close(fd);
    return 0;
}

threadpool.h

#ifndef _THREADPOOL_H
#define _THREADPOOL_H
 
typedef struct ThreadPool ThreadPool;
// 创建线程池并初始化
ThreadPool *threadPoolCreate(int min, int max, int queueCapacity);
 
// 销毁线程池
int threadPoolDestroy(ThreadPool* pool);
 
// 给线程池添加任务
void threadPoolAdd(ThreadPool* pool, void(*func)(void*), void* arg);
 
// 获取线程池中工作的线程的个数
int threadPoolBusyNum(ThreadPool* pool);
 
// 获取线程池中活着的线程的个数
int threadPoolAliveNum(ThreadPool* pool);
 
//
// 工作的线程(消费者线程)任务函数
void* worker(void* arg);
// 管理者线程任务函数
void* manager(void* arg);
// 单个线程退出
void threadExit(ThreadPool* pool);
#endif  // _THREADPOOL_H
 

threadpool.c

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "threadpool.h"
const int NUMBER = 2;
 
// 任务结构体
typedef struct Task
{
    void (*function)(void* arg);
    void* arg;
}Task;
 
// 线程池结构体
struct ThreadPool
{
    // 任务队列
    Task* taskQ;
    int queueCapacity;  // 容量
    int queueSize;      // 当前任务个数
    int queueFront;     // 队头 -> 取数据
    int queueRear;      // 队尾 -> 放数据
 
    pthread_t managerID;    // 管理者线程ID
    pthread_t *threadIDs;   // 工作的线程ID
    int minNum;             // 最小线程数量
    int maxNum;             // 最大线程数量
    int busyNum;            // 忙的线程的个数
    int liveNum;            // 存活的线程的个数
    int exitNum;            // 要销毁的线程个数
    pthread_mutex_t mutexPool;  // 锁整个的线程池
    pthread_mutex_t mutexBusy;  // 锁busyNum变量
    pthread_cond_t notFull;     // 任务队列是不是满了
    pthread_cond_t notEmpty;    // 任务队列是不是空了
 
    int shutdown;           // 是不是要销毁线程池, 销毁为1, 不销毁为0
};
 
// 创建线程池并初始化
ThreadPool* threadPoolCreate(int min, int max, int queueCapacity)
{
    ThreadPool* pool = (ThreadPool*)malloc(sizeof(ThreadPool));
    do 
    {
        if (pool == NULL)
        {
            printf("malloc threadpool fail...\n");
            break;
        }
 
        pool->threadIDs = (pthread_t*)malloc(sizeof(pthread_t) * max);
        if (pool->threadIDs == NULL)
        {
            printf("malloc threadIDs fail...\n");
            break;
        }
        memset(pool->threadIDs, 0, sizeof(pthread_t) * max);
        pool->minNum = min;
        pool->maxNum = max;
        pool->busyNum = 0;
        pool->liveNum = min;    // 和最小个数相等
        pool->exitNum = 0;
 
        if (pthread_mutex_init(&pool->mutexPool, NULL) != 0 ||
            pthread_mutex_init(&pool->mutexBusy, NULL) != 0 ||
            pthread_cond_init(&pool->notEmpty, NULL) != 0 ||
            pthread_cond_init(&pool->notFull, NULL) != 0)
        {
            printf("mutex or condition init fail...\n");
            break;
        }
 
        // 任务队列
        pool->taskQ = (Task*)malloc(sizeof(Task) * queueCapacity);
        pool->queueCapacity = queueCapacity;
        pool->queueSize = 0;
        pool->queueFront = 0;
        pool->queueRear = 0;
 
        pool->shutdown = 0;
 
        // 创建线程
        pthread_create(&pool->managerID, NULL, manager, pool);
        for (int i = 0; i < min; ++i)
        {
            pthread_create(&pool->threadIDs[i], NULL, worker, pool);
        }
        return pool;
    } while (0);
 
    // 释放资源
    if (pool && pool->threadIDs) free(pool->threadIDs);
    if (pool && pool->taskQ) free(pool->taskQ);
    if (pool) free(pool);
 
    return NULL;
}
 
// 销毁线程池
int threadPoolDestroy(ThreadPool* pool)
{
    if (pool == NULL)
    {
        return -1;
    }
 
    // 关闭线程池
    pool->shutdown = 1;
    // 阻塞回收管理者线程
    pthread_join(pool->managerID, NULL);
    // 唤醒阻塞的消费者线程
    for (int i = 0; i < pool->liveNum; ++i)
    {
        pthread_cond_signal(&pool->notEmpty);
    }
    // 释放堆内存
    if (pool->taskQ)
    {
        free(pool->taskQ);
    }
    if (pool->threadIDs)
    {
        free(pool->threadIDs);
    }
 
    pthread_mutex_destroy(&pool->mutexPool);
    pthread_mutex_destroy(&pool->mutexBusy);
    pthread_cond_destroy(&pool->notEmpty);
    pthread_cond_destroy(&pool->notFull);
 
    free(pool);
    pool = NULL;
 
    return 0;
}
 
// 给线程池添加任务
void threadPoolAdd(ThreadPool* pool, void(*func)(void*), void* arg)
{
    pthread_mutex_lock(&pool->mutexPool);
    while (pool->queueSize == pool->queueCapacity && !pool->shutdown)
    {
        // 阻塞生产者线程
        pthread_cond_wait(&pool->notFull, &pool->mutexPool);
    }
    if (pool->shutdown)
    {
        pthread_mutex_unlock(&pool->mutexPool);
        return;
    }
    // 添加任务
    pool->taskQ[pool->queueRear].function = func;
    pool->taskQ[pool->queueRear].arg = arg;
    pool->queueRear = (pool->queueRear + 1) % pool->queueCapacity;
    pool->queueSize++;
 
    pthread_cond_signal(&pool->notEmpty);
    pthread_mutex_unlock(&pool->mutexPool);
}
 
// 获取线程池中工作的线程的个数
int threadPoolBusyNum(ThreadPool* pool)
{
    pthread_mutex_lock(&pool->mutexBusy);
    int busyNum = pool->busyNum;
    pthread_mutex_unlock(&pool->mutexBusy);
    return busyNum;
}
 
// 获取线程池中活着的线程的个数
int threadPoolAliveNum(ThreadPool* pool)
{
    pthread_mutex_lock(&pool->mutexPool);
    int aliveNum = pool->liveNum;
    pthread_mutex_unlock(&pool->mutexPool);
    return aliveNum;
}
 
// 工作的线程(消费者线程)任务函数
void* worker(void* arg)
{
    ThreadPool* pool = (ThreadPool*)arg;
 
    while (1)
    {
        pthread_mutex_lock(&pool->mutexPool);
        // 当前任务队列是否为空
        while (pool->queueSize == 0 && !pool->shutdown)
        {
            // 阻塞工作线程
            pthread_cond_wait(&pool->notEmpty, &pool->mutexPool);
 
            // 判断是不是要销毁线程
            if (pool->exitNum > 0)
            {
                pool->exitNum--;
                if (pool->liveNum > pool->minNum)
                {
                    pool->liveNum--;
                    pthread_mutex_unlock(&pool->mutexPool);
                    threadExit(pool);
                }
            }
        }
 
        // 判断线程池是否被关闭了
        if (pool->shutdown)
        {
            pthread_mutex_unlock(&pool->mutexPool);
            threadExit(pool);
        }
 
        // 从任务队列中取出一个任务
        Task task;
        task.function = pool->taskQ[pool->queueFront].function;
        task.arg = pool->taskQ[pool->queueFront].arg;
        // 移动头结点
        pool->queueFront = (pool->queueFront + 1) % pool->queueCapacity;
        pool->queueSize--;
        // 解锁
        pthread_cond_signal(&pool->notFull);
        pthread_mutex_unlock(&pool->mutexPool);
 
        printf("thread %ld start working...\n", pthread_self());
        pthread_mutex_lock(&pool->mutexBusy);
        pool->busyNum++;
        pthread_mutex_unlock(&pool->mutexBusy);
        task.function(task.arg);
        free(task.arg);
        task.arg = NULL;
 
        printf("thread %ld end working...\n", pthread_self());
        pthread_mutex_lock(&pool->mutexBusy);
        pool->busyNum--;
        pthread_mutex_unlock(&pool->mutexBusy);
    }
    return NULL;
}
 
// 管理者线程任务函数
void* manager(void* arg)
{
    ThreadPool* pool = (ThreadPool*)arg;
    while (!pool->shutdown)
    {
        // 每隔3s检测一次
        sleep(3);
 
        // 取出线程池中任务的数量和当前线程的数量
        pthread_mutex_lock(&pool->mutexPool);
        int queueSize = pool->queueSize;
        int liveNum = pool->liveNum;
        pthread_mutex_unlock(&pool->mutexPool);
 
        // 取出忙的线程的数量
        pthread_mutex_lock(&pool->mutexBusy);
        int busyNum = pool->busyNum;
        pthread_mutex_unlock(&pool->mutexBusy);
 
        // 添加线程
        // 任务的个数>存活的线程个数-忙的线程 && 存活的线程数<最大线程数
        if (queueSize > liveNum-busyNum && liveNum < pool->maxNum)
        {
            pthread_mutex_lock(&pool->mutexPool);
            int counter = 0;
            for (int i = 0; i < pool->maxNum && counter < NUMBER
                && pool->liveNum < pool->maxNum; ++i)
            {
                if (pool->threadIDs[i] == 0)
                {
                    pthread_create(&pool->threadIDs[i], NULL, worker, pool);
                    counter++;
                    pool->liveNum++;
                }
            }
            pthread_mutex_unlock(&pool->mutexPool);
        }
        // 销毁线程
        // 忙的线程*2 < 存活的线程数 && 存活的线程>最小线程数
        if (busyNum * 2 < liveNum && liveNum > pool->minNum)
        {
            pthread_mutex_lock(&pool->mutexPool);
            pool->exitNum = NUMBER;
            pthread_mutex_unlock(&pool->mutexPool);
            // 让工作的线程自杀
            for (int i = 0; i < NUMBER; ++i)
            {
                pthread_cond_signal(&pool->notEmpty);
            }
        }
    }
    return NULL;
}
 
// 单个线程退出
void threadExit(ThreadPool* pool)
{
    pthread_t tid = pthread_self();
    for (int i = 0; i < pool->maxNum; ++i)
    {
        if (pool->threadIDs[i] == tid)
        {
            pool->threadIDs[i] = 0;
            printf("threadExit() called, %ld exiting...\n", tid);
            break;
        }
    }
    pthread_exit(NULL);
}

运行效果:

gcc server.c threadpool.c -lpthread -o server

./server
heheda@heheda:~/Linux/DB_teacher$ ./server
thread 140278235014912 start working...
thread 140278218229504 start working...
客户端的IP: 192.168.88.129,端口: 50356
client say: 你好,呵呵哒,0...

client say: 你好,呵呵哒,1...

client say: 你好,呵呵哒,2...

thread 140278226622208 start working...
客户端的IP: 192.168.88.129,端口: 50362
client say: 你好,呵呵哒,0...

client say: 你好,呵呵哒,3...

client say: 你好,呵呵哒,1...

client say: 你好,呵呵哒,4...

client say: 你好,呵呵哒,2...

client say: 你好,呵呵哒,5...

client say: 你好,呵呵哒,3...

thread 140278207641344 start working...
客户端的IP: 192.168.88.129,端口: 50378
client say: 你好,呵呵哒,0...

client say: 你好,呵呵哒,6...

client say: 你好,呵呵哒,4...

client say: 你好,呵呵哒,1...

client say: 你好,呵呵哒,7...

client say: 你好,呵呵哒,5...

client say: 你好,呵呵哒,2...

client say: 你好,呵呵哒,8...

thread 140278128178944 start working...
客户端的IP: 192.168.88.129,端口: 58904
client say: 你好,呵呵哒,0...

client say: 你好,呵呵哒,6...

client say: 你好,呵呵哒,3...

client say: 你好,呵呵哒,9...

client say: 你好,呵呵哒,1...

client say: 你好,呵呵哒,7...

client say: 你好,呵呵哒,4...

client say: 你好,呵呵哒,10...

client say: 你好,呵呵哒,2...

client say: 你好,呵呵哒,8...

client say: 你好,呵呵哒,5...

client say: 你好,呵呵哒,11...

client say: 你好,呵呵哒,3...

client say: 你好,呵呵哒,9...

client say: 你好,呵呵哒,6...

client say: 你好,呵呵哒,12...

client say: 你好,呵呵哒,4...

client say: 你好,呵呵哒,10...

client say: 你好,呵呵哒,7...

client say: 你好,呵呵哒,13...

client say: 你好,呵呵哒,5...

client say: 你好,呵呵哒,11...

client say: 你好,呵呵哒,8...

client say: 你好,呵呵哒,14...

client say: 你好,呵呵哒,6...

client say: 你好,呵呵哒,12...

client say: 你好,呵呵哒,9...

client say: 你好,呵呵哒,15...

client say: 你好,呵呵哒,7...

client say: 你好,呵呵哒,13...

client say: 你好,呵呵哒,10...

client say: 你好,呵呵哒,16...

client say: 你好,呵呵哒,8...

client say: 你好,呵呵哒,14...

client say: 你好,呵呵哒,11...

client say: 你好,呵呵哒,17...

client say: 你好,呵呵哒,9...

client say: 你好,呵呵哒,15...

client say: 你好,呵呵哒,12...

client say: 你好,呵呵哒,18...

client say: 你好,呵呵哒,10...

client say: 你好,呵呵哒,16...

client say: 你好,呵呵哒,13...

client say: 你好,呵呵哒,19...

client say: 你好,呵呵哒,11...

client say: 你好,呵呵哒,17...

client say: 你好,呵呵哒,14...

client say: 你好,呵呵哒,20...

client say: 你好,呵呵哒,12...

client say: 你好,呵呵哒,18...

client say: 你好,呵呵哒,15...

客户端已经断开了连接...
thread 140278218229504 end working...
client say: 你好,呵呵哒,13...

client say: 你好,呵呵哒,19...

client say: 你好,呵呵哒,16...

client say: 你好,呵呵哒,14...

客户端已经断开了连接...
thread 140278226622208 end working...
client say: 你好,呵呵哒,17...

client say: 你好,呵呵哒,15...

client say: 你好,呵呵哒,18...

客户端已经断开了连接...
thread 140278207641344 end working...
client say: 你好,呵呵哒,16...

client say: 你好,呵呵哒,17...

客户端已经断开了连接...
thread 140278128178944 end working...
threadExit() called, 140278218229504 exiting...
threadExit() called, 140278226622208 exiting...

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/822682.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Jmeter如何添加插件

一、前言 ​ 在我们的工作中&#xff0c;我们可以利用一些插件来帮助我们更好的进行性能测试。今天我们来介绍下Jmeter怎么添加插件&#xff1f; 2023最新Jmeter接口测试从入门到精通&#xff08;全套项目实战教程&#xff09; 二、插件管理器 ​ 首先我们需要下载插件管理器j…

一个完整的http请求响应过程

一、 HTTP请求和响应步骤 图片来自&#xff1a;理解Http请求与响应 以上完整表示了HTTP请求和响应的7个步骤&#xff0c;下面从TCP/IP协议模型的角度来理解HTTP请求和响应如何传递的。 二、TCP/IP协议 TCP/IP协议模型&#xff08;Transmission Control Protocol/Internet Pr…

04、并发用户数该怎么计算

什么是并发&#xff1f; 我们假设上图中的这些小人是严格按照这个逻辑到达系统的&#xff0c;那显然&#xff0c;系统的绝对并发用户数是 4。如果描述 1 秒内的并发用户数&#xff0c;那就是 16。是不是显而易见&#xff1f;但是&#xff0c;在实际的系统中&#xff0c;用户通常…

若依框架 - 对二次封装数据分页

LsDistrictController /*** 查询地段列表*/ApiOperation("查询地段列表")GetMapping("/list")public TableDataInfo list(LsDistrict lsDistrict) {startPage();Map<String, List> map lsDistrictService.selectLsDistrictList(lsDistrict);if (Col…

java类和对象详解(1)

面向对象的初步认知 什么是面向对象 Java是一门纯面向对象的语言(Object Oriented Program, 简称OOP),在面向对象的世界里&#xff0c;一切皆为对象。面向对象是解决问题的一种思想&#xff0c;主要依靠对象之间的交互完成一件事情。 用面向对象的思想来涉及程序&#xff0c;更…

AntdesignVue 时间设置为年份不回显问题解决

时间设置为年份回显时报如下错误 年份设置值后报value异常 解决方案 格式不一致导致的 moment格式化后是string类型&#xff0c;后台返回的是Number类型导致的&#xff0c;统一格式就会显示了

人工智能安全-3-噪声数据处理

0 提纲 噪声相关概述噪声处理的理论与方法基于数据清洗的噪声过滤主动式过滤噪声鲁棒模型1 噪声相关概述 噪声类型: 属性噪声:样本中某个属性的值存在噪声标签噪声:样本归属类别关于噪声分布的假设:均匀分布、高斯分布、泊松分布等。 标签噪声的产生原因: (1)特定类别…

Unity 引擎做残影效果——1、BakeMesh

Unity实现残影效果 大家好&#xff0c;我是阿赵。   这次来分享一下在Unity里面做残影的效果。   所谓的残影&#xff0c;就是在角色移动的过程中&#xff0c;留下一串残留的影子。 这种效果比较常出现在格斗游戏和动作游戏。   在Unity里面做残影&#xff0c;方法很多…

DSPM来袭!什么是数据安全态势管理

数据安全态势管理是一种保护云数据的方法&#xff0c;通过确保敏感数据始终具有正确的安全态势&#xff0c;无论其被复制或移动到何处。 那么&#xff0c;什么是DSPM&#xff1f;这是一个简单的例子&#xff1a; 假设您已经为云数据建立了出色的安全态势。在此示例中&#xf…

力扣 96. 不同的二叉搜索树

题目来源&#xff1a;https://leetcode.cn/problems/unique-binary-search-trees/description/ C题解&#xff1a;动归五部曲。 确定dp数组以及下标的含义。dp[i] &#xff1a; 1到i为节点组成的二叉搜索树的个数为dp[i]。确定递推公式。由于是二叉搜索树&#xff0c;我们可以…

vue实现 图片拖拽及鼠标滚轮放大缩小

效果&#xff1a; 代码实现 <template><div class"container"><divclass"image-container"mousewheel.stop"onMouseWheel"mousedown"onMouseDown"mousemove"onMouseMove"mouseleave"onMouseLeave&quo…

大文件传输的有效可用方式

如何传输大文件&#xff1f;大文件传输的方法有哪些&#xff1f;在互联网时代&#xff0c;速度就是效率。企业在生产过程中需要进行数据信息的交换、转移。这就涉及到大文件的传输。不同的行业都有大文件传输的需求。比如影视行业需要每天传输视频素材&#xff0c;一个视频可能…

第十三章 利用PCA简化数据

文章目录 第十三章 利用PCA简化数据13.1降维技术13.2PCA13.2.1移动坐标轴 13.2.2在NumPy中实现PCA13.3利用PCA对半导体制造数据降维 第十三章 利用PCA简化数据 PCA&#xff08;Principal Component Analysis&#xff0c;主成分分析&#xff09;是一种常用的降维技术&#xff0…

Error in v-on handler (Promise/async): “[object Object]“

解决方法&#xff1a;用try 和 catch 语句来处理 catch来接收try异常报错

Linux怎么设置软链接(ln命令)

在Linux中&#xff0c;软链接&#xff08;Symbolic Link&#xff09;&#xff0c;它可以指向另一个文件或目录。类似于Windows中的快捷方式。 主要作用&#xff1a;文件路径简化&#xff1a;通过创建软链接&#xff0c;可以将长而复杂的文件路径简化为一个易于记忆和使用的链接…

【大数据之Flume】四、Flume进阶之复制和多路复用、负载均衡和故障转移、聚合案例

1 复制和多路复用 &#xff08;1&#xff09;需求&#xff1a;使用 Flume-1 监控文件变动&#xff08;可以用Exec Source或Taildir Source&#xff09;&#xff0c;Flume-1 将变动内容传递给 Flume-2&#xff08;用Avro Sink传&#xff09;&#xff0c;&#xff08;用Avro Sou…

ES6基础知识九:你是怎么理解ES6中Module的?使用场景?

一、介绍 模块&#xff0c;&#xff08;Module&#xff09;&#xff0c;是能够单独命名并独立地完成一定功能的程序语句的集合&#xff08;即程序代码和数据结构的集合体&#xff09;。 两个基本的特征&#xff1a;外部特征和内部特征 外部特征是指模块跟外部环境联系的接口…

iMacros WebBrowser Component for .NET

iMacros WebBrowser Component for .NET 在几分钟内实现应用程序自动化 快速轻松地将iMacro集成到您的应用程序中。不需要单独的安装程序。 无缝集成 iMacros与您的.NET应用程序无缝集成&#xff0c;作为Microsoft WebBrowser控件的替代品。它甚至可以用作每个.NET应用程序中的…

C++报错 XX does not name a type;field `XX’ has incomplete type解决方案

C报错 XX does not name a type&#xff1b;field XX’ has incomplete type解决方案 两个C编译错误及解决办法–does not name a type和field XX’ has incomplete type 编译错误一&#xff1a;XX does not name a type 编译错误二&#xff1a;field XX’ has incomplete t…

【云原生】Serverless 技术架构分析

一、什么是Serverless? 1、Serverless技术简介 ​ Serverless&#xff08;无服务器架构&#xff09;指的是由开发者实现的服务端逻辑运行在无状态的计算容器中&#xff0c;它由事件触发&#xff0c; 完全被第三方管理&#xff0c;其业务层面的状态则被开发者使用的数据库和存…