Inheritance: ChromecastChannel
        public async Task Initialize(string host, string port, ConnectionChannel connectionChannel, HeartbeatChannel heartbeatChannel, Action<Stream, bool> packetReader)
        {
            if (_client == null) _client = new TcpSocketClient();
            await _client.ConnectAsync(host, int.Parse(port), true, default(CancellationToken), true);


            connectionChannel.OpenConnection();
            heartbeatChannel.StartHeartbeat();

            await Task.Run(() =>
            {
                while (true)
                {
                    var sizeBuffer = new byte[4];
                    byte[] messageBuffer = { };
                    // First message should contain the size of message
                    _client.ReadStream.Read(sizeBuffer, 0, sizeBuffer.Length);
                    // The message is little-endian (that is, little end first),
                    // reverse the byte array.
                    Array.Reverse(sizeBuffer);
                    //Retrieve the size of message
                    var messageSize = BitConverter.ToInt32(sizeBuffer, 0);
                    messageBuffer = new byte[messageSize];
                    _client.ReadStream.Read(messageBuffer, 0, messageBuffer.Length);
                    var answer = new MemoryStream(messageBuffer.Length);
                    answer.Write(messageBuffer, 0, messageBuffer.Length);
                    answer.Position = 0;
                    packetReader(answer, true);
                }
            });
        }
 public ChromeCastClient()
 {
     ChromecastSocketService = new ChromecastSocketService();
     Channels = new List<IChromecastChannel>();
     ConnectionChannel = new ConnectionChannel(this);
     Channels.Add(ConnectionChannel);
     HeartbeatChannel = new HeartbeatChannel(this);
     Channels.Add(HeartbeatChannel);
     ReceiverChannel = new ReceiverChannel(this);
     Channels.Add(ReceiverChannel);
     MediaChannel = new MediaChannel(this);
     Channels.Add(MediaChannel);
 }