public void HandleCommunication() { _sReader = new StreamReader(_client.GetStream(), Encoding.UTF8); _sWriter = new StreamWriter(_client.GetStream(), Encoding.UTF8); _isConnected = _client.Connected; String sData = null; while (_isConnected) { _isConnected = _client.Connected; if (_isConnected == false) { break; } Console.Write("(Client)Введите ссобщение "); sData = TextEncryptor.Encrypt(Console.ReadLine(), Settings.node.node_encrypt_key); if (sData == "exit") { _sWriter.WriteLine(sData); _sWriter.Flush(); break; } // write data and make sure to flush, or the buffer will continue to // grow, and your data might not be sent when you want it, and will // only be sent once the buffer is filled. _sWriter.WriteLine(sData); _sWriter.Flush(); // if you want to receive anything String sDataIncomming = TextEncryptor.Decrypt(_sReader.ReadLine(), Settings.node.node_private_key); Console.WriteLine("(Client)Answer from server: " + sDataIncomming); } _sReader.Close(); _sWriter.Close(); Environment.Exit(-1); }
public void HandleClient(object obj) { // retrieve client from parameter passed to thread TcpClient client = (TcpClient)obj; // sets two streams StreamWriter sWriter = new StreamWriter(client.GetStream(), Encoding.UTF8); StreamReader sReader = new StreamReader(client.GetStream(), Encoding.UTF8); // you could use the NetworkStream to read and write, // but there is no forcing flush, even when requested Boolean bClientConnected = true; String sData = null; log.Info("Client connected: " + ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString()); while (bClientConnected) { // reads from stream sData = TextEncryptor.Decrypt(sReader.ReadLine(), Settings.node.node_encrypt_key); // shows content on the console. log.Info("(Server)Client data: " + sData); Console.WriteLine("(Server)Client data: " + sData); if (sData == "exit") { break; } // to write something back. sWriter.WriteLine(sData); sWriter.Flush(); } sWriter.Close(); sReader.Close(); }
public static string Decrypt(this string source, TextEncryptor enc, string code) { return(enc.Decrypt(source, code)); }
public static LoginToken ParseToken(string loginToken, TextEncryptor signer) { AssertUtils.AssertNotNull(loginToken); return(JsonConvert.DeserializeObject <LoginToken>(signer.Decrypt(loginToken))); }