会安装 valgrind 来告诉我问题出在哪里,但不幸的是这台计算机上不能有任何新程序......谁能告诉我这个“回声”程序是否存在明显问题?为朋友这样做,所以不确定客户端的布局是什么,但我知道读取和写入都是有效的套接字描述符,并且我已经测试了 n = write(writes,"I got your消息\n",20); 和 n = write(reads,"I got your message \n",20); 两者都有效,因此可以确认这不是无效 fd 的情况。谢谢!
int
main( int argc, char** argv ) {
int reads = atoi(argv[1]) ;
int writes = atoi(argv[3]) ;
int n ;
char buffer[MAX_LINE];
memset(buffer, 0, sizeof(buffer));
int i = 0 ;
while (1) {
read(reads, buffer, sizeof(buffer));
n = write(writes,buffer,sizeof(buffer));
if (n < 0) perror("ERROR reading from socket");
}