Bloxy.BloxyServer._Send C# (CSharp) Method

_Send() private method

private _Send ( char command, byte message ) : void
command char
message byte
return void
        private void _Send(char command, byte[] message)
        {
            //Build the whole buffer
              var msg = new byte[message.Length + 1];
              msg[0] = (byte)command;
              Array.Copy(message, 0, msg, 1, message.Length);

              //Connect if we need to
              if (_client == null)
              {
            _client = new TcpClient();
            _client.Connect(_server, _outport);
              }

              //Put the length in front of it (needs to be combined with above, I know)
              var m = new byte[msg.Length + 4];
              m[0] = (byte)(msg.Length & 0xFF);
              m[1] = (byte)((msg.Length >> 8) & 0xFF);
              m[2] = (byte)((msg.Length >> 16) & 0xFF);
              m[3] = (byte)((msg.Length >> 24) & 0xFF);
              Array.Copy(msg, 0, m, 4, msg.Length);

              //Send it off
              var stream = _client.GetStream();
              stream.Write(m, 0, m.Length);
              stream.Flush();
        }