static void Main(string[] args) { try { TCPfile obj_server = new TCPfile(); System.Threading.Thread obj_thread = new System.Threading.Thread(obj_server.StartServer); obj_thread.Start(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Read(); } }
static void Main(string[] args) { IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0]; TcpListener server = new TcpListener(ip, 1111); TcpClient client = default(TcpClient); try { TCPfile obj_server = new TCPfile(); System.Threading.Thread obj_thread = new System.Threading.Thread(obj_server.StartServer); obj_thread.Start(); server.Start(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Read(); } while (true) { client = server.AcceptTcpClient(); byte[] receivedBuffer = new byte[889911]; NetworkStream stream = client.GetStream(); stream.Read(receivedBuffer, 0, receivedBuffer.Length); Char[] chars = { ' ' }; string Fname; string Lname; string Email; string Pass; string ID; string IP; //! = first name //@ = last name //# = Email //$ = Pass StringBuilder msg = new StringBuilder(); foreach (byte b in receivedBuffer) { if (b.Equals(00)) //or 59 { break; } else { msg.Append(Convert.ToChar(b).ToString()); } } string[] names = msg.ToString().Split(chars); foreach (string x in names) { //Console.WriteLine(x); if (x.StartsWith("!") && x.EndsWith("!")) { Fname = x.Substring(1, x.Length - 2); //To check Console.WriteLine(Fname); } else if (x.StartsWith("@") && x.EndsWith("@")) { Lname = x.Substring(1, x.Length - 2); //To check Console.WriteLine(Lname); } else if (x.StartsWith("#") && x.EndsWith("#")) { Email = x.Substring(1, x.Length - 2); //To check Console.WriteLine(Email); } else if (x.StartsWith("$") && x.EndsWith("$")) { Pass = x.Substring(1, x.Length - 2); //To check Console.WriteLine(Pass); } else if (x.StartsWith("%") && x.EndsWith("%")) { ID = x.Substring(1, x.Length - 2); //To check Console.WriteLine(ID); } else if (x.StartsWith("^") && x.EndsWith("^")) { IP = x.Substring(1, x.Length - 2); //To check //Console.WriteLine(IP); //I DONT WANT ANYBODY TO KNOW MY IP ADDRESS } } //Console.WriteLine(msg.ToString() + " " + "bytes: " + msg.Length); } }