C# Socket receive data and send and receive again
<p>I have a lot of GPS devices. One of my device (as client) send this message every minutes on TCP "[3G*4700201934*0009*LK,0,1,61]"</p>

<p>and my server have to read the message from GPS device and reply to device, I mean my server must send this message "[3G*4700201934*0009*LK]" for getting GPS positions. If I can't send this message, GPS device doesn't send the positions of GPS. </p>

<p>My code:</p>

<pre><code>TcpListener listener = new TcpListener(IPAddress.Any, port);
listener.Start();

//Sonsuz döngü sayesinde AgAkimini sürekli okuyoruz
while (true)
{
    Socket client = listener.AcceptSocket();
    Console.WriteLine("Connection accepted.");

    var childSocketThread = new Thread(() =&gt;
    {
        byte[] data = new byte[100];
        int size = client.Receive(data);
        string fromGPSMessage = string.Empty;
        for (int i = 0; i &lt; size; i++)
            fromGPSMessage += Convert.ToChar(data[i]);
        Console.WriteLine("Recieved data: " + fromGPSMessage);
        //fromGPSMessage = [3G*4700201934*0009*LK,0,1,59]
        string serverMessageToGPS = fromGPSMessage.Substring(0, fromGPSMessage.IndexOf(",")) + "]";
        //serverMessageToGPS = [3G*4700201934*0009*LK]
        Encoding ascii = Encoding.ASCII;
        client.Send(ascii.GetBytes(serverMessageToGPS));

        data = new byte[100];
        size = client.Receive(data);
        string newMessagefromGPSMessage = string.Empty;
        for (int i = 0; i &lt; size; i++)
            newMessagefromGPSMessage += Convert.ToChar(data[i]);
        Console.WriteLine("New Message Data: " + newMessagefromGPSMessage);

        client.Close();
    });
    childSocketThread.Start();
}
</code></pre>

<p>sometimes there is no new message data:</p>

<p><a href="https://i.stack.imgur.com/CxIgQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CxIgQ.png" alt="enter image description here"></a></p>

<p>I can send message to device but I don't know how to get second message from GPS device. </p>