private void InitView() { Content = new StackLayout() { Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0), Children = { new ClientConnectView("127.0.0.1", 11000, this) { ConnectTapped = async(s, i) => { await _client.ConnectAsync(s, i); _canceller = new CancellationTokenSource(); Task.Factory.StartNew(() => { foreach (var msg in _client.ReadStrings(_canceller.Token)) { _messagesSub.OnNext(msg); } }, TaskCreationOptions.LongRunning); return(true); }, DisconnectTapped = async() => { var bytes = Encoding.UTF8.GetBytes("<EOF>"); await _client.WriteStream.WriteAsync(bytes, 0, bytes.Length); await _client.WriteStream.FlushAsync(); _canceller.Cancel(); await _client.DisconnectAsync(); } }, new MessagesView(_messagesObs, true) { SendData = async s => { await _client.WriteStringAsync(s); return(new Message { Text = s, DetailText = String.Format("Sent at {0}",DateTime.Now.ToString("HH:mm:ss")) }); } } } }; }