// Collection of code snippets by Arne Vajhøj // posted to eksperten.dk, usenet and other places (2002-now) using System; using System.IO; using System.Net.Sockets; using System.Threading; public class ChatClient { public static void Main(string[] args) { TcpClient client = new TcpClient("localhost", 50000); StreamWriter wrt = new StreamWriter(client.GetStream()); (new Thread(new ThreadStart((new Reader(client)).Run))).Start(); string line; while((line = Console.ReadLine()) != null) { wrt.WriteLine("SEND " + line); wrt.Flush(); } wrt.WriteLine("EXIT"); wrt.Flush(); wrt.Close(); client.Close(); } } public class Reader { private StreamReader rdr; public Reader(TcpClient cli) { rdr = new StreamReader(cli.GetStream()); } public void Run() { try { string line; while((line = rdr.ReadLine()) != null) { Console.WriteLine(line); } } catch(Exception) { // nothing } } }