static void Main(string[] args) { ChatClient client = new ChatClient(); AppDomain.CurrentDomain.ProcessExit += client.ShutDown; client.Start(); }
static void Main(string[] args) { client = new ChatClient(591, IPAddress.Parse("127.0.0.1")); string mode, message, name; client.PacketRecieved += ProcessPacket; client.Start(); Console.WriteLine("--------------Client started--------------"); Console.Write("Do you want to register (r) or to login (l): "); mode = Console.ReadLine(); if (mode == "r") { Console.Write("Enter your name: "); name = Console.ReadLine(); client.CurrentUser = new User(name, client.ClientPort, client.ClientIP); client.SendPacket(new RegistrationRequestPacket(client.CurrentUser)); while (true) { message = Console.ReadLine(); client.SendPacket(new MessagePacket(client.CurrentUser, message)); } } else if (mode == "l") { //Implemention of logging system } }
public static void Main(string[] args) { var client = new ChatClient(); client.OnGotInfo += (o, e) => { foreach (var f in e.OnlineUsers) Console.WriteLine(f); }; client.OnGotMessage += (o, e) => Console.WriteLine($"Got message fron {e.SourceId}! {e.ChatContent}"); client.OnGotError += (o, e) => { if (e.Error == ErrorKind.DuplicateId) Console.WriteLine("Duplicated ID!"); }; client.Start(); while(true) { try { Console.WriteLine("Input ID!"); var idStr = Console.ReadLine(); var id = Int32.Parse(idStr); client.LogOn(id).Wait(); break; } catch(AggregateException e) { e.Handle(ex => ex is DuplicateIdException); } } while (true) { var input = Console.ReadLine(); try { var m = Regex.Match(input, @"^\s*(?<command>\S*)"); if (m.Success) { var collection = m.Groups["command"]; switch (collection.ToString()) { case "sendto": var subStr = input.Substring(m.Index + "sendto".Length); var m2 = Regex.Match(subStr, @"\s*(?<id>\d+)\s+(?<message>.*)"); if (m2.Success) { client.Chat(Int32.Parse(m2.Groups["id"].ToString()), m2.Groups["message"].ToString()); } break; default: Console.WriteLine("Unsupported!"); break; } } } finally { } } }
public static void Main(string[] args) { try { var ip = System.Configuration.ConfigurationManager.AppSettings["ip"]; var port = System.Configuration.ConfigurationManager.AppSettings["port"]; IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip), int.Parse(port)); using (var chatClient = new ChatClient(endPoint)) { chatClient.Start(); chatClient.Write(); } } catch (SocketException ex) { Console.WriteLine(ex.Message); } }