The program hangs because you have a while(true)
loop in EthStartB_Click
which runs on UI thread. clientStream.Read
call will block UI thread.
Move the receive logic on a new thread and set the textbox
content using Control.Invoke
or Dipatcher.Invoke
depending on whether you are on WinForms or WPF - and do that only if you do have some content in the message
to be written to textbox.
There also another issue, since you have the tcpClient.Close()
outside the while
loop on the server, neither client nor server will disconnect. Both will block on their respective stream.Read
calls.
Since you are running both client and server on same machine, that TcpListener ClientListener
is not required and will not play well with the server already listening on the same port.