i am trying to link a Unity game to a Java server using C#
when the Java server up the only way i can send data is by closing the StreamWriter (OUT.Close();) which actually closes the connection too. so i can only send data onces. or, every time i want to send a message, i have to reconnect to the server again.
when i just use Flush(), the data will not be send to the server.
Code:
NetworkStream STREAM = connection.GetStream();
StreamWriter OUT = new StreamWriter(STREAM);
OUT.Write(text);
OUT.Flush()
this is my reading code:
BufferedReader input = new BufferedReader(new InputStreamReader(client.getInputStream()));
String inputstring = input.readLine();
You write text without a line separator with
Writeand read withReadLine, so this doesn’t match up. In the absence of line separators,ReadLinereads to the end of the stream, which explains why you need to close the stream. ReplaceWritewithWriteLine.