Exemple #1
0
    static void Main(string[] args)
    {
        Console.Title = "Cliente";

        try {
            client        = new TcpClient("127.0.0.1", 7777);
            ins           = new StreamReader(client.GetStream());
            ots           = new StreamWriter(client.GetStream());
            ots.AutoFlush = true;
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        if (client != null && ots != null && ins != null)
        {
            try {
                cThread ct       = new cThread(client, ins, ots);
                Thread  ctThread = new Thread(ct.run);
                ctThread.Start();

                while (!ct.closed)
                {
                    string msg = Console.ReadLine().Trim();
                    ots.WriteLine(msg);
                }
                ots.Close();
                ins.Close();
                client.Close();
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
    }
Exemple #2
0
    static void Main(string[] args)
    {
        try {
            client = new TcpClient("127.0.0.1", 7777);
            ins = new StreamReader(client.GetStream());
            ots = new StreamWriter(client.GetStream());
            ots.AutoFlush = true;
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        if (client != null && ots != null && ins != null) {
            try {
                cThread cli = new cThread(client, ins, ots);
                Thread ctThread = new Thread(cli.run);
                ctThread.Start();

                while (!cli.closed) {
                    string msg = Console.ReadLine().Trim();
                    ots.WriteLine(msg);
                }
                ots.Close();
                ins.Close();
                client.Close();
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
    }