I send it like this:
byte[] data = Encoding.Unicode.GetBytes(message); stream.Write(data, 0, data.Length); I accept it like this:
byte[] data = new byte[64]; // буфер для получаемых данных while (true) { // получаем сообщение StringBuilder builder = new StringBuilder(); int bytes = 0; do { bytes = stream.Read(data, 0, data.Length); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); } while (stream.DataAvailable); string message = builder.ToString(); Console.WriteLine(message); // TODO } Such a method is suitable for passing a string or say int. And how to transfer an array and in addition to complex numbers Complex [] ??
while (DataAvailable)- what if the server will transfer more slowly than the client read? - VladDwhile (totalBytes < neededBytes) totalBytes += await stream.ReadAsync(...);). - VladD