/// <summary> /// Send a message to the specified client. /// </summary> /// <param name="ipPort">The IP:port of the client.</param> /// <param name="data">Data to send to the client.</param> /// <returns>True if successful.</returns> public bool Send(string ipPort, byte[] data) { if (Wtcp == null) { if (Debug) { Console.WriteLine("Server is null, cannot send"); } return(false); } if (Wtcp.IsClientConnected(ipPort)) { Wtcp.Send(ipPort, data); return(true); } else { if (Debug) { Console.WriteLine("Server is not connected, cannot send"); } return(false); } }
static void Main(string[] args) { Console.Write("Server IP : "); serverIp = Console.ReadLine(); Console.Write("Server Port : "); serverPort = Convert.ToInt32(Console.ReadLine()); Console.Write("Certificate File : "); certFile = Console.ReadLine(); Console.Write("Certificate Pass : "******"Command [? for help]: "); string userInput = Console.ReadLine(); List <string> clients; string ipPort; if (String.IsNullOrEmpty(userInput)) { continue; } switch (userInput) { case "?": Console.WriteLine("Available commands:"); Console.WriteLine(" ? help (this menu)"); Console.WriteLine(" q quit"); Console.WriteLine(" cls clear screen"); Console.WriteLine(" list list clients"); Console.WriteLine(" send send message to client"); Console.WriteLine(" remove disconnect client"); break; case "q": runForever = false; break; case "cls": Console.Clear(); break; case "list": clients = server.ListClients(); if (clients != null && clients.Count > 0) { Console.WriteLine("Clients"); foreach (string curr in clients) { Console.WriteLine(" " + curr); } } else { Console.WriteLine("None"); } break; case "send": Console.Write("IP:Port: "); ipPort = Console.ReadLine(); Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } server.Send(ipPort, Encoding.UTF8.GetBytes(userInput)); break; case "remove": Console.Write("IP:Port: "); ipPort = Console.ReadLine(); server.DisconnectClient(ipPort); break; default: break; } } } }