# Socket read issue on long running primary interface

**URL:** <https://forum.universal-robots.com/t/socket-read-issue-on-long-running-primary-interface/3304>\
**Category:** Robot Communication\
**Created:** [December 13, 2018, 4:39pm UTC](https://forum.universal-robots.com/t/socket-read-issue-on-long-running-primary-interface/3304 "2018-12-13T16:39:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniele.genero](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@daniele.genero](https://forum.universal-robots.com/u/daniele.genero)\
**Post date:** [December 13, 2018, 4:39pm UTC](https://forum.universal-robots.com/t/socket-read-issue-on-long-running-primary-interface/3304/1 "2018-12-13T16:39:50Z")

</div>

Hi guys,  
I’ve implemented the primary interface protocol in C# for reading robot infos.  
I’m in trouble with a long running socket read. After a few tens of minutes the connection is interrupted, generating an exception on NetworkStream.Read command:

> ```
> System.IO.IOException: Impossibile leggere dati dalla connessione del trasporto: Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato. ---> System.Net.Sockets.SocketException: Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato
> in System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
> 
> ```

This is my snippet C# code:

```
var TcpConnection = new TcpClient();
TcpConnection.ReceiveBufferSize = 1024 * 32;// ; Int32.MaxValue;
TcpConnection.ReceiveTimeout = 6000;
TcpConnection.SendTimeout = 6000;
TcpConnection.ExclusiveAddressUse = true;
TcpConnection.NoDelay = true;
TcpConnection.Connect("192.168.0.5", 30001);
var s = TcpConnection.GetStream();
s.ReadTimeout = 5000;
s.WriteTimeout = 5000;
var byte[] b = new byte[1024 * 32];
while(true) {
  var streamLenght = s.Read(b, 0, b.Length);

  // ... PARSING PACKETS HERE ...

  Thread.Sleep(50);
}

```

Any help?  
Thanks
