I have an app with a TCP Listener, and a remote client constantly sending data (once per second).
Using Hercules Setup utility as a server I am able to receive the data, but when I use my own application the data isn't displayed in the textBox.
All I can see in my app is that the length is 266- which is what I expect, but the data is just expressed as 2 rectangle boxes.
What could be the issue here?
public void bgWorkerSocketListener_DoWork(object sender, DoWorkEventArgs e)
{
try
{
AppendTextBox2("Waiting for a connection... " + Environment.NewLine);
server = new TcpListener(localAddr, port);
server.Start();
Byte[] bytes = new Byte[4096];
String data = null;
while (true)
{
client = server.AcceptTcpClient();
AppendTextBox2("Connected!" + Environment.NewLine);
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
AppendTextBox2("Length: " + data.Length + " Received: " + data);
}
}
}
catch (SocketException ex)
{
MessageBox.Show("SocketException: " + ex);
}
}
AppendTextBox2 is just an invoke method for appending my text box from another thread:
public void AppendTextBox2(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendTextBox2), new object[] { value });
return;
}
tBoxTcpIpStatus.Text += value;
tBoxTcpIpStatus.SelectionStart = tBoxTcpIpStatus.TextLength;
tBoxTcpIpStatus.ScrollToCaret();
}
What I have tried:
Any idea what could be happening here?
It's not my append method, I already tried to remove it, without success.