# TCP/IP Communication with C - read\_ascii\_float () issue

**URL:** <https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313>\
**Category:** Robot Communication\
**Created:** [May 14, 2020, 2:54pm UTC](https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313 "2020-05-14T14:54:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cslouis](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@cslouis](https://forum.universal-robots.com/u/cslouis)\
**Post date:** [May 14, 2020, 2:54pm UTC](https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313/1 "2020-05-14T14:54:45Z")

</div>

Hi - Newbie mistake that I posted this initially in a closed thread. Here it is as a new thread.

Hello - I have been following this (TCP/IP Communication with C++) thread and have a question. I got this to work but I only get the updated data[] after I stop the robot program and then restart.

I have my socket open connection in a thread. After the connection is made, I then send the ready message to my connected pc, then the pc sends the 4 values in Data[]. but if I view at the Data[] in the variables on the pendant, while running the program, they don’t update until I stop the program.

Am I not allowed to run the socket in a thread? Do I need to continually open and then close the socket for each data exchange or can I keep it open until the program ends?

Here is the program If you don’t mind taking a look. I initialize the Data[] and other variables. Connection is working and I am receiving the other data from the UR as expected.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/e/eeef7b0dfe2112f1e91d6594670a21dd169bce8f.jpeg)

Thank you!!

---

<div class="post-metadata">

**Author:** ![mvrooij](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mvrooij/32/2151_2.png) [@mvrooij](https://forum.universal-robots.com/u/mvrooij)\
**Post date:** [May 27, 2020, 9:27pm UTC](https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313/2 "2020-05-27T21:27:12Z")

</div>

Perhaps you’ve missed my answer in that thread to your question, so here’s a re-post of my answer:

When a socket closes, any pending data is flushed to the receiving application. The reason why you won’t get is sooner is because you didn’t complete the data packet from the PC side. Missing ) perhaps?

---

<div class="post-metadata">

**Author:** ![anon52592067](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@anon52592067](https://forum.universal-robots.com/u/anon52592067)\
**Post date:** [November 9, 2021, 3:57am UTC](https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313/3 "2021-11-09T03:57:16Z")

</div>

- I used Winsocket on the server to send data:  
string sendBuf = “(00110001, 00110001, 00110001)”;  
send(sClient, (const char \*)&sendBuf, strlen((const char \*)&sendBuf), 0);  
Socket\_read\_ascii\_float () used on UR side could not receive data ， Do you know the reason?  
Do you know which format to send data in winsocket and socket\_read\_ASCIi\_float () on UR to receive data correctly.  
Looking forward to your reply.  
Thanks

---

<div class="post-metadata">

**Author:** ![mvrooij](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mvrooij/32/2151_2.png) [@mvrooij](https://forum.universal-robots.com/u/mvrooij)\
**Post date:** [November 9, 2021, 7:25pm UTC](https://forum.universal-robots.com/t/tcp-ip-communication-with-c-read-ascii-float-issue/7313/4 "2021-11-09T19:25:27Z")

</div>

I believe the “float” values should be a string literal, eg “56.3” So as a “human readable” format. SendBuf = “53.4”; would be decoded by Socket\_read\_ascii\_float() correctly. Since your version has 3 fields seperated by comma’s, the robot will decode it as an array of data, but invalid since the first number should be the number of items in that array.
