Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux中的基本网络对读取函数的子序列调用 我在Linux环境下使用C++编写了代码>库。我很难理解读写功能。它们没有像我预期的那样工作,缓冲区可能没有清空?我阅读了关于read函数的文档,它最多可以读取65000个字节。我知道必须有办法读取更多数据并清空缓冲区,等等_C++_C_Linux_Networking - Fatal编程技术网

Linux中的基本网络对读取函数的子序列调用 我在Linux环境下使用C++编写了代码>库。我很难理解读写功能。它们没有像我预期的那样工作,缓冲区可能没有清空?我阅读了关于read函数的文档,它最多可以读取65000个字节。我知道必须有办法读取更多数据并清空缓冲区,等等

Linux中的基本网络对读取函数的子序列调用 我在Linux环境下使用C++编写了代码>库。我很难理解读写功能。它们没有像我预期的那样工作,缓冲区可能没有清空?我阅读了关于read函数的文档,它最多可以读取65000个字节。我知道必须有办法读取更多数据并清空缓冲区,等等,c++,c,linux,networking,C++,C,Linux,Networking,我有一个客户端-服务器程序,客户端多次调用write函数,如下所示 for(int i=0;i<5;i++) { int n = write(socketFileDescriptor,"I got your message",18); if (n < 0) socketError("ERROR writing to socket"); } void* run(void* arg) { ServerSocket*

我有一个客户端-服务器程序,客户端多次调用write函数,如下所示

    for(int i=0;i<5;i++)
    {   
        int n = write(socketFileDescriptor,"I got your message",18);
        if (n < 0) socketError("ERROR writing to socket");
    }
void* run(void* arg)
{
    ServerSocket* ss = (ServerSocket*)arg;
    while(true)
    {
        char buffer[256];
        bzero(buffer,256);
        int n = read(ss->newsockfd,buffer,256);
        printf("Here is the message: %s",buffer);
    }

}
我得到的不是5个版本的发送字符串,而是25个版本


这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息:这里是消息消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:消息:

你是说你有25次读取,每次读取0字节?那么如何脱离循环呢?因此run方法在pthread库中的一个单独的linux线程中运行。因此,该线程的目的是持续读取并打印所读取的内容。从您的输出来看,您的
read()
似乎返回0。如果它是一个普通的阻塞套接字,则表示您的套接字已关闭。通常当套接字关闭时退出循环。哈哈,你是对的!非常感谢。让我再玩一会儿-没有好的字符串可供使用,我得10分!好了,现在我一次就收到了所有的信息。因此,客户端循环5次,而服务器只循环一次并接收该消息。您知道如何刷新读/写缓冲区并手动发送数据吗?