# Socket communication to get integer & float arrays

**URL:** <https://forum.universal-robots.com/t/socket-communication-to-get-integer-float-arrays/3690>\
**Category:** Robot Communication\
**Created:** [February 20, 2019, 4:26am UTC](https://forum.universal-robots.com/t/socket-communication-to-get-integer-float-arrays/3690 "2019-02-20T04:26:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederic.chaxel](https://avatars.discourse-cdn.com/v4/letter/f/b487fb/32.png) [@frederic.chaxel](https://forum.universal-robots.com/u/frederic.chaxel)\
**Post date:** [February 20, 2019, 4:26am UTC](https://forum.universal-robots.com/t/socket-communication-to-get-integer-float-arrays/3690/1 "2019-02-20T04:26:04Z")

</div>

Hi,

Got very strange behaviour with socket communication, getting both float values & integer with socket\_read\_binary\_integer and socket\_get\_ascii\_float in the same code .

```
UAOpen=False
while True:

if UAOpen!=True :
	UAOpen=socket_open("127.0.0.1", 4841,"socket_UA")
else:
	socket_send_string("float","socket_UA")
	global UA_InputsFloat=socket_read_ascii_float(24,"socket_UA")
	socket_send_string("int","socket_UA")
	global UA_InputsInt=socket_read_binary_integer(24,"socket_UA")
end

```

end

Using it the integer array values are wrong : 3 bytes right shifted !!! The float array still OK.  
When putting a comment for float request all is OK with the integers.

But it’s also OK using two separated sockets, such as:

```
while True:

if UAOpen!=True :
	UAOpen=socket_open("127.0.0.1", 4841,"socket_F")
	socket_open("127.0.0.1", 4841,"socket_I")
else:
	socket_send_string("int","socket_I")
	global UA_InputsInt=socket_read_binary_integer(24,"socket_I")
	socket_send_string("float","socket_F")
	global UA_InputsFloat=socket_read_ascii_float(24,"socket_F")
end

```

end

Any idea ?

Server in C# code, same problem with gcc application:

```
 static void Main(string[] args)
    {
        ListenForClients();

    }

    private static void ListenForClients()
    {
        try
        {
            TcpListener tcpListener = new TcpListener(IPAddress.Any, 4841);

            tcpListener.Start();

            for (; ; )
            {

                TcpClient client = tcpListener.AcceptTcpClient();

                Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
                clientThread.IsBackground = true;
                clientThread.Start(client);
            }
        }
        catch { }
    }

    private static void HandleClientComm(object client)
    {
        TcpClient tcpClient = (TcpClient)client;
        NetworkStream clientStream = tcpClient.GetStream();

        byte[] buffer = new byte[256];

        try
        {
            for (; ; )
            {
                int nb = tcpClient.Client.Receive(buffer);
                Console.WriteLine(Encoding.ASCII.GetString(buffer));
                if (Encoding.ASCII.GetString(buffer).Contains("int"))
                {
                    byte[] Reponse = new byte[4 * 24];

                    for (int i=0;i<24;i++)
                    {
                        byte[] b = BitConverter.GetBytes(i);
                        Array.Reverse(b);
                        Array.Copy(b, 0, Reponse, i * 4, 4);
                    }

                    tcpClient.Client.Send(Reponse);

                }
                else
                {
                    String s = "(";
                    for (int i = 0; i < 24; i++)
                        if (i != 23)
                            s = s + i.ToString() + ",";
                        else
                            s = s + i.ToString() + ")\n";

                    tcpClient.Client.Send(Encoding.ASCII.GetBytes(s));
                }
            }

        }
        catch { }
    }
```
