# socket **Repository Path**: neu103_robot/socket ## Basic Information - **Project Name**: socket - **Description**: No description available - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-07-06 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 说明 - 这是一个简单的socket库 - 发送数据加入了校验,心跳检测(未实现),数据长度 - 分别实现了以下几种方式进行通信 - 功能:server和client相互发送数据 #### 1.普通方式 #### 2.多进程方式:https://www.coder4.com/archives/151 ```c #创建子进程 fork() #子进程回收 signal(SIGCHLD, handler); static void handler(int num) { //接受SIGCHLD的信号,然后进行线程回收 int status; // 返回终止子进程的进程ID。并将该子进程的终止状态存放在有status指向的存储单元中 int pid = waitpid(-1, &status, WNOHANG); // -1 等待所有子进程 WNOHANG 不阻塞模式 if (WIFEXITED(status)) { // 若此值为非0 表明进程正常结束 printf("The child process %d exit\n", pid); } } ``` #### 3.多线程方式:https://blog.csdn.net/Shreck66/article/details/50412986 ```c #需要自己实现一个线程池 thread_pool.h #如何在类中使用线程 std::bind(&SocketServer::run_handler,this,remote_addr,_client_sockfd) ```