I am trying to develop a simple sender/listener TCP/IP socket in C#; i.e. once connected, the sender application reads a character string typed in a textbox and sends it to a listener Windows Application throgh a syncronous TCP/IP socket. The listener code is here
receivingExit = true;
btnStopReceiving.Enabled = true;
btnStartReceiving.Enabled = false;
while (receivingExit) {
byte[] bytes = new byte[1024];
MessageBox.Show("Waiting !!!"); //Line to be commented
int bytesRec = workingSocket.Receive(bytes);
MessageBox.Show("Received "+bytesRec+" bytes"); //Line to be commented
String data =Encoding.ASCII.GetString(bytes,0,bytesRec);
MessageBox.Show(data); //Line to be commented
txtDiplay.Text = txtDiplay.Text+data+"\r\n";
}
If I leave the comments, everything works fine; i.e. in txtDisplay text box I can see the characters string I typed and sent by my sender application.... obviously I see the MessageBox(es) displaying; but once inserted the comments as above, it seems the listener Windows App blocks after get the connection with the sender and anything appears in txtDisplay... the same issue if I use a syncronous UDP/IP socket. With console application instaed, everything works fine. What the problems, and how could solve them ? Advanced thanks. Davide