class Program { static void Main(string[] args) { TcpListener server = null; try { var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); var ipAddress = IPAddress.Parse("xx.x.xx.x"); server = new TcpListener(ipAddress, Port); // Start listening for client requests. server.Start(); Console.WriteLine("server started"); // Buffer for reading data byte[] bytes = new Byte[1024]; string data = null; // Enter the listening loop. while (true) { // Perform a blocking call to accept requests. TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Connected!"); data = null; // Get a stream object for reading and writing NetworkStream stream = client.GetStream(); int i; // Loop to receive all the data sent by the client. while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); string pathString = ""; if (data.Contains(XXX)) { pathString = Path.Combine(folderName, "XXX"); } else if (data.Contains(AAA)) { pathString = Path.Combine(folderName, "AAA"); } else if (data.Contains(BBB)) { pathString = Path.Combine(folderName, "BBB"); } else { pathString = Path.Combine(folderName, "Unrouteable"); } if (!Directory.Exists(pathString)) { Directory.CreateDirectory(pathString); } CreateTextFile(pathString, "fsdfsdf.txt", data); } // Shutdown and end connection client.Close(); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } finally { // Stop listening for new clients. server.Stop(); } Console.ReadLine(); } private static void CreateTextFile(string path, string textTitle, string data) { var pathString = Path.Combine(path, textTitle); if (!File.Exists(pathString)) { File.Create(pathString).Close(); using (var tw = new StreamWriter(pathString)) { tw.WriteLine(data); } } } }
File.Create(pathString).Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)