public bool Connect(string ID) { bool Stoppable = true; Thread Stopper = new Thread(new ThreadStart(() => { Thread.Sleep(10 * 1000); try { if (Stoppable) { Listener.EndConnect(null); } } catch { } })); try { Stopper.Start(); while (Connection == null) { Client NewClient = new Client(Listener.Accept()); Stoppable = false; Stopper.Abort(); string ClientID = NewClient.Receive(); if (ClientID == ID) { // Match NewClient.Send("1"); Connection = NewClient; return true; } else { // Invalid client NewClient.Send("0"); } } } catch { return false; } return false; }
public static void Registration(Socket socket) { Client client = new Client(socket, id++); clients.Add(client); client.Send(new RegistrationResultMessage(client.Id)); Task task = new Task(client.Listen); task.Start(); }