public static async Task <string> ReadMessageAsync(this IConnectionClient tcpClient)
        {
            if (!tcpClient.Connected)
            {
                return(null);
            }

            var networkStream = tcpClient.GetStream();
            var reader        = new StreamReader(networkStream);

            return(await reader.ReadLineAsync());
        }
Esempio n. 2
0
        public ResponseSender(IConnectionClient tcpClient)
        {
            _tcpClient = tcpClient;
            if (!tcpClient.Connected)
            {
                throw new ClientIsNotConnectException();
            }
            Connected = true;
            var networkStream = tcpClient.GetStream();

            _streamWriter = new StreamWriter(networkStream, Encoding.ASCII);
            _streamReader = new StreamReader(networkStream, Encoding.ASCII);
        }
        public static async Task <bool> WriteMessageAsync(this IConnectionClient tcpClient, string message)
        {
            if (!tcpClient.Connected)
            {
                return(false);
            }
            var networkStream = tcpClient.GetStream();
            var writer        = new StreamWriter(networkStream);
            await writer.WriteLineAsync(message);

            writer.Flush();

            return(true);
        }
Esempio n. 4
0
 public void Close()
 {
     _tcpClient.GetStream().Close();
     _tcpClient.Close();
     Connected = false;
 }