1

I am using a terminal as a host to input data (via copy/paste an arbitrary set of characters into the terminal). I want to capture this stream of data in my application.

I am using this code sample as a client to listen to the host. However, the output I receive is a small string, not equal to the size of the buffer. I anticipated the code to print out the string, equal to the size of the buffer.

> buffer size = 100;
> --
> sample input (copy/pasted into terminal): "here is a random string" 
>
> current output: "h" 
> expected output: "here is a random string"

How would I capture this "live" stream of data and have output consistent with the buffer, instead of a small string?

4

2 回答 2

2

经过一番调查,该recv()功能不能保证收集我想要的所有数据。

为此,我遵循:https ://stackoverflow.com/a/12696176/1121302

现在,我得到了预期的输出。

于 2013-09-30T21:12:57.167 回答
0

看起来他们使用的是 UDP 协议,而不是保证交付和订单的 TCP。甚至您链接的页面在页面的中途也提到了这一点。

请记住:使用 UDP 数据报套接字发送的数据不能保证到达!

于 2013-09-30T21:07:45.857 回答