Z.P. Z.P. - 6 days ago 7
C# Question

White character C# textbox



I am new in C# and I have a problem with square white characters in textbox in C#. (see screenshot below)

I have implemented client-server program for chatting which is supported by

System.Net.Sockets.
Inside each program is
byte[] array= new byte[10025]
, which is never totally full, but textbox shows blank characters inside. Can you help me with deletion of this characters?


Thank you!


Blank white character squares

Read code of client side:

http://pastebin.com/W3Pc3BPG

try
{
while (true)
{
serverStream = clientSocket.GetStream();
int buffSize = 0;
byte[] inStream = new byte[10025];
buffSize = clientSocket.ReceiveBufferSize;
serverStream.Read(inStream, 0, inStream.Length);
string returndata = System.Text.Encoding.UTF8.GetString(inStream);
readData = "" + returndata;
msg();
}
} catch(Exception e)
{
ctThread.Join();
}

RB. RB.
Answer
serverStream = clientSocket.GetStream();
int buffSize = 0;
byte[] inStream = new byte[10025];
buffSize = clientSocket.ReceiveBufferSize;
// Make sure you respect the number of bytes that have been read.
// Note that the below code is not the most performant - it's just
// to demonstrate the technique. 
int bytesRead = serverStream.Read(inStream, 0, inStream.Length);
byte[] theData = inStream.Take(bytesRead).ToArray();
string returndata = System.Text.Encoding.UTF8.GetString(theData);
readData = "" + returndata;
msg();
Comments