# Cinder-Asio TCP Error

**URL:** <https://discourse.libcinder.org/t/cinder-asio-tcp-error/1037>\
**Category:** Using Cinder\
**Created:** [January 31, 2018, 9:37am UTC](https://discourse.libcinder.org/t/cinder-asio-tcp-error/1037 "2018-01-31T09:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![b\_ndsh\_h](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@b\_ndsh\_h](https://discourse.libcinder.org/u/b_ndsh_h)\
**Post date:** [January 31, 2018, 9:37am UTC](https://discourse.libcinder.org/t/cinder-asio-tcp-error/1037/1 "2018-01-31T09:37:25Z")

</div>

Hey,

first of all many thanks for your amazing work with Cinder. I’ve been using it since a few years now.

I run into a problem using [Cinder-Asio](https://github.com/BanTheRewind/Cinder-Asio) - it may be lack of knowledge.

While TCP-Communictaion between a server and a client i get the following error-message after a while:

_“An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.”_

Is a TCP-Session supposed to be closed after every message/communication?  
Is UDP a better choice for a steady client/server state request?

Regards from Berlin.

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [January 31, 2018, 4:13pm UTC](https://discourse.libcinder.org/t/cinder-asio-tcp-error/1037/2 "2018-01-31T16:13:02Z")

</div>

Hi,

without knowing specific details about your code, it’s safe to say that it’s probably a matter of not reading (or writing) your network messages often enough. All network code uses memory buffers to write messages to and store messages received. But it’s then up to you to process those messages and remove them from the buffer before it gets filled to the brim.

Not sure if ASIO is prone to this issue, but one thing I ran into in the past that caused a buffer overflow was something like this:

```auto
if( hasMessageReceived )
    processMessage();

```

, which would simply read a single message per update. That, of course, caused an overflow as soon as I started to receive thousands of little messages per second. This would have been better (and solved the problem):

```auto
while( hasMessageReceived )
    processMessage();

```

FYI: a TCP should not be closed after every message. It’s why you’re using TCP in the first place: to keep the connection alive. UDP is connection-less, so you simply send a message and you don’t really care about the receiver at all. UDP is faster, but more prone to errors, especially on a busy network or over long distances.

-Paul
