static void Main(string[] args) { Socket socket = NetHelper.TcpSocketHelper.CreateSocket(); socket.Bind(new IPEndPoint(IPAddress.Loopback, 57650)); Console.WriteLine($"{NetHelper.UsefulThings.GetPublicIpAddress()}:57650"); socket.Listen(10); while (true) { Socket temp = socket.Accept(); Data data = NetHelper.TcpSocketHelper.Receive(temp); if (data.GetString() == "d") { temp.Send(NetHelper.UsefulThings.ToBytes(DateTime.Now.Date.ToShortDateString())); Console.WriteLine("Date Sent!"); } else if (data.GetString() == "t") { temp.Send(NetHelper.UsefulThings.ToBytes(DateTime.Now.TimeOfDay.ToString())); Console.WriteLine("Time Sent!"); } else { temp.Send(NetHelper.UsefulThings.ToBytes(DateTime.Now.ToString(CultureInfo.InvariantCulture))); Console.WriteLine("Full Sent!"); } temp.Shutdown(SocketShutdown.Both); } }
static void Main(string[] args) { Socket socket = NetHelper.TcpSocketHelper.CreateSocket(); Console.Write("IP: "); IPAddress ip = IPAddress.Parse(Console.ReadLine() ?? string.Empty); Console.Write("PORT: "); int port = int.Parse(Console.ReadLine() ?? string.Empty); Console.WriteLine("Date ('d') or Time ('t') or Full ('f')"); string choice; while (true) { choice = Console.ReadLine(); if (choice.ToLower() == "d" || choice.ToLower() == "t" || choice.ToLower() == "f") { break; } } socket.Connect(new IPEndPoint(ip, port)); socket.Send(NetHelper.UsefulThings.ToBytes(choice)); Data data = NetHelper.TcpSocketHelper.Receive(socket); Console.WriteLine(data.GetString()); Console.Read(); }