コード例 #1
0
ファイル: Server.cs プロジェクト: hnefatl/Iliad-IV
        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;
        }
コード例 #2
0
ファイル: BigStaticClass.cs プロジェクト: Boykooo/Boom
        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();
        }