#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#define N 128
#define ERRLOG(msg) do{\
printf("%s %s %d:", __FILE__, __func__, __LINE__);\
perror(msg);\
exit(-1);\
}while(0)
void *data_recv_send(void *arg){
msg_t msg = *(msg_t *)arg;
int nbytes = 0;
char buff[N] ={0};
printf("客户端[%s:%d]连接到服务器\n",inet_ntoa(msg.clientaddr.sin_addr),ntohs(msg.clientaddr.sin_port));
while(1){
memset(buff,0,N);
//接收客户端发来的数据
if(-1 == (nbytes = recv(msg.acceptfd,buff,N,0))){
ERRLOG("recv error");
}else if(0 == nbytes){
printf("客户端[%s:%d]与服务器断开连接...\n",inet_ntoa(msg.clientaddr.sin_a
C# 使用多线程实现TCP并发服务器
于 2022-10-19 19:49:48 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)