public async Task SendAsync(string message) { byte[] data = Cryptographic.Encrypt(message, "123"); try { //Write Lenght message in buffer _writer.WriteInt32(data.Length); //Write message in buffer _writer.WriteBytes(data); //Send buffer await _writer.StoreAsync(); //Clear buffer await _writer.FlushAsync(); } catch (Exception ex) { InvokeOnError(ex.Message); } }
private async Task ReadAsync() { _reader = new DataReader(_socket.InputStream); try { //If Close while (!_cancel.IsCancellationRequested) { //Wait recive some data byte[] data = await ReceiveData(_reader); IBuffer buffer = data.AsBuffer(); //Decrypt message string text = Cryptographic.Decrypt(buffer, "123"); //Invoke event when message Recive InvokeOnDataRecEive(text); } } catch (Exception e) { InvokeOnError(e.Message); } }