getting response from server through callback

This commit is contained in:
Sem van der Hoeven
2020-09-25 13:41:54 +02:00
parent fac3987678
commit 23f146afdd
2 changed files with 32 additions and 21 deletions

View File

@@ -27,21 +27,28 @@ namespace RH_Engine
if (this.callback == null)
{
throw new Exception("Callback not initialized!");
} else
while (true)
}
else
{
Console.WriteLine("Starting loop for reading");
while (true)
{
string res = ReadPrefMessage(Stream);
//Console.WriteLine("[SERVERRESPONSEREADER] got message from server: " + res);
this.callback(res);
}
}
});
t.Start();
}
public static string ReadPrefMessage(NetworkStream stream)
{
byte[] lengthBytes = new byte[4];
stream.Read(lengthBytes, 0, 4);
Console.WriteLine("read message..");
int streamread = stream.Read(lengthBytes, 0, 4);
Console.WriteLine("read message.. " + streamread);
int length = BitConverter.ToInt32(lengthBytes);