Created
April 23, 2013 17:22
-
-
Save choucavalier/5445592 to your computer and use it in GitHub Desktop.
Revisions
-
Valentin Iovene created this gist
Apr 23, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ TcpListener server = new TcpListener(_ipAddress, _port); server.Start(); Console.WriteLine("Listening on port " + _port); Byte[] bytes = new byte[256]; while (true) { try { TcpClient client = server.AcceptTcpClient(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("New client connected :D"); NetworkStream stream = client.GetStream(); bool isOutput = stream.ReadByte() == 1; if (!isOutput) { Console.WriteLine("He wants to talk! :O"); Console.ForegroundColor = ConsoleColor.White; int i; while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { Console.WriteLine(" > " + Encoding.ASCII.GetString(bytes, 0, i)); stream.WriteByte(1); } } stream.Close(); client.Close(); } }