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?

2 Answers2

2

After some investigation, the recv() function is not guaranteed to gather all data I want.

To do this, I followed: https://stackoverflow.com/a/12696176/1121302

Now, I get my expected output.

Community
  • 1
  • 1
0

It looks like they are using the UDP protocol and not TCP which guarantees the delivery and order. Even the page you linked mentioned this half way down the page.

Remember: data sent using UDP datagram sockets isn't guaranteed to arrive!

Freddie
  • 871
  • 6
  • 10
  • ***[More](http://www.microhowto.info/howto/listen_for_and_receive_udp_datagrams_in_c.html)*** on the topic. – ryyker Sep 30 '13 at 21:11