title: Socket sending long strings of null
body: <p>Hi guys i have an issue currently when using a Socket to send data.</p>
  
  <p>I am currently getting a very strange issue when a Client sends to the server, for example "HEART", as a heart beat. afer sending the first time the server starts receiving a whole lot of \0, not always the same amount before the HEART. I am using queues to queue up sending so on slow connections it waits for the current send to be done before it sends the next but for tiny lengths like that i'm a bit confused.</p>
  
  <pre><code>    public void Send(string data)
      {
          if (Connected)
          {
              SendQueue.Enqueue(data);
              if (t.ThreadState == ThreadState.Stopped)
              {
                  t = new Thread(new ThreadStart(SendData));
                  t.Start();
              }
              else if (t.ThreadState == ThreadState.Unstarted)
                  t.Start();
          }
      }
  </code></pre>
  
  <p>and the SendData function</p>
  
  <pre><code>    private void SendData()
      {
          if (sending)
              return;
          sending = true;
          while (SendQueue.Count &gt; 0)
          {
              if (ClientSocket.Connected)
              {
                  byte[] data = Networking.StringToByte((string)SendQueue.Dequeue());
                  ClientSocket.Send(data);
              }
          }
          sending = false;
      }
  </code></pre>
  
  <p>i don't think it's the sending function because i've debugged it and the byte array always holds the correct info.</p>
  
  <p>the receiving end is even simpler.</p>
  
  <pre><code>    public string Receive()
      {
          string msg = "";
          if (Connected)
          {
              byte[] data = new byte[1024];
              while (ClientSocket.Avaliable &gt; 0)
              {
                  ClientSocket.Receive(data);
                  msg += Networking.ByteToString(data).Trim();
              }
          }
          return msg;
      }
  </code></pre>
  
  <p>If anyone could point out where i'm going wrong or if i've gone at this the entirely wrong way that would be great.
  Thanks guys.</p>
  
  <p>I will remind people that it's seemingly random lengths of \0 each 2 seconds (in this example for the HEART message heartbeat)</p>