Dear all,
I’m actually sending data from Matlab to update a UNITY scene :
- Matlab send “a” or “b” to UNITY, using TCP protocol
- UNITY receive “a” or “b”, and update the color of an object based on this character
I’ve got an issue with the update of my variable called “coherence” in UNITY. When the script is running, packets of data coming from MATLAB are concatenating. For exemple, if I print “coherence” in the log file, it looks like “aaaaababbbbbbbbaaaaabbbbbbababababbbbaaababbaabbbaba”. What I would like, is my last packet of data to be the only one to be read and print (e.g, “coherence” is “a”, then “b”, then “b”, then “a” and so on, instead of being “a” then “ab” then “abb” then “abba” …).
Can you tell me if something is wrong in my code please ?
Thanks a lot for your input,
Yannick
// Use this for initialization of TCP Server
TcpListener listener;
String coherence;
// Initialization of the script
void Start()
{
_renderer = GetComponent();
listener = new TcpListener(55001);
listener.Start();
print(“is listening”);
}
void Update()
{
if (!listener.Pending())
{
}
else
{
print("socket comes");
TcpClient client = listener.AcceptTcpClient();
NetworkStream ns = client.GetStream();
StreamReader reader = new StreamReader(ns);
coherence = reader.ReadToEnd();
print(coherence);
}
if (coherence == "a")
{
colorFin = Color.green;
}
else if (coherence == "b")
{
colorFin = Color.yellow;
}
}