Il mio problema è questo, ho un thread che gestiche una connessione socket, cioè il cuore del thread ha la funzione di inviare una stringa (interrogazione) e ricevere la risposta.
Il mio problema è che al primo giro del thread tutto funziona cioè l'host mi risponde con la stringa che mi aspetto, ma dopo il primo giro non risponde più...
andando step per step sembra che dopo l'invio dell recieve la connessione si chiude, cioè l apriprietà dell'oggetto Socket.Connected = false.
Qualcuno mi sa dire se sto sbagliando ad usare l'oggetto o ha un'idea di cosa sto sbaglindo??

public Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);

private void Form1_Load(object sender, EventArgs e)
{
workerThread = new Thread(this.DoWork);
workerThread.IsBackground = true;
// Start the worker thread.
workerThread.Start();
Application.DoEvents();
}


public void DoWork()
{
Byte[] bytes = new Byte[1024];
Byte[] msg = Encoding.ASCII.GetBytes("@01RD000800005F*\r\0");
//array di appoggio dei dati in arrivo
ArraySegment<Byte> DatiInArrivo = new ArraySegment<Byte>(bytes);
Byte[] ReciveBytes = new Byte[s.ReceiveBufferSize];
//
while (!_shouldStop)
{
// Use the SelectWrite enumeration to obtain Socket status.
if (s.Poll(-1, SelectMode.SelectWrite))
{
Console.WriteLine("This Socket is writable.");
MessageBox.Show("This Socket is writable.", "", MessageBoxButtons.OK);
}


try
{
Int32 bytesent = s.Send(msg);
Int32 ReciveOperationflag = s.Receive(DatiInArrivo.Array);
String Response = Encoding.ASCII.GetString(bytes, 0, ReciveOperationflag);

MessageBox.Show("Send: " + Encoding.ASCII.GetString(msg, 0, bytesent) + " Recive: " + Response, "", MessageBoxButtons.OK);
MessageBox.Show("Recive: " + Response, "", MessageBoxButtons.OK);
Thread.Sleep(5000);
}
catch (ArgumentNullException ane)
{
Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
MessageBox.Show("ArgumentNullException :" + ane.ToString(), "Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (SocketException se)
{
Console.WriteLine("SocketException : {0}", se.ToString());
MessageBox.Show("SocketException :" + se.ToString(), "Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
MessageBox.Show("Unexpected exception :" + e.ToString(), "Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}