public void SetServer(TcpServer server) { this.server = server; }
/* 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.ASCII); * StreamReader sReader = new StreamReader(client.GetStream(), Encoding.ASCII); * // you could use the NetworkStream to read and write, * // but there is no forcing flush, even when requested * * Boolean bClientConnected = true; * String sData = null; * * while (bClientConnected) * { * // reads from stream * sData = sReader.ReadLine(); * * // shows content on the console. * Console.WriteLine("Client > " + sData); * * // to write something back. * * if(sData =="askpiece") * { * sWriter.WriteLine("piecegiven"); * sWriter.Flush(); * } * if (sData == "line") * { * sWriter.WriteLine("linedone"); * sWriter.Flush(); * } * if (sData == "finished") * { * sWriter.WriteLine("gj"); * sWriter.Flush(); * * } * * * } * } */ static void Main(string[] args) { Console.WriteLine("Multi-Threaded TCP Server Demo"); TcpServer server = new TcpServer(5555); }