First of all set your TCP Task in Another Thread than your current context thread. the reason of your TCP listener that stuck is no action from your server side application you or implementation.
here is one my client side code I've used to send random byte array and get some information from server and also i used thread for best result As you could see below
try
{
tcpThread = new Thread(new ThreadStart(tcpMethod));
tcpThread.Start();
}
catch (Exception)
{
MessageBox.Show("Error in Running Thread!");
}
#region TCP Connection Method
private void tcpMethod()
{
try
{
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect("192.168.5.32", 9696);
byte[] array = new byte[512];
Random random = new Random();
random.NextBytes(array);
Stream stm = tcpclnt.GetStream();
stm.Write(array, 0, array.Length);
byte[] result = new byte[512];
stm.Read(result, 0, 512);
tcpclnt.Close();
}
catch (Exception exception)
{
MessageBox.Show("Error In reading TCP Server : " + exception.StackTrace);
}
}
#endregion