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 { }
}