예제 #1
0
        private void client_StatusChanged(ServerSocketBelongTo arg2, ServerSocketItem arg3)
        {
            lock (lock_clientList) {
                if (arg3.BelongTo == ServerSocketBelongTo.Handshake && arg2 == ServerSocketBelongTo.Normal)
                {
                    handshakeList.Remove(arg3.Guid);
                    normalList.Add(arg3.UserName, arg3);
                    arg3.BelongTo = arg2;
                    return;
                }
                if (arg3.BelongTo == ServerSocketBelongTo.Handshake && arg2 == ServerSocketBelongTo.RTR)
                {
                    handshakeList.Remove(arg3.Guid);
                    rtrList.Add(arg3);
                    arg3.BelongTo = arg2;
                    return;
                }
                if (arg3.BelongTo == ServerSocketBelongTo.Normal && arg2 == ServerSocketBelongTo.RTR)
                {
                    normalList.Remove(arg3.UserName);
                    rtrList.Add(arg3);
                    arg3.BelongTo = arg2;
                    return;
                }
                if (arg2 == ServerSocketBelongTo.Close)
                {
                    switch (arg3.BelongTo)
                    {
                    case ServerSocketBelongTo.Handshake:
                        normalList.Remove(arg3.Guid);
                        break;

                    case ServerSocketBelongTo.Normal:
                        normalList.Remove(arg3.UserName);
                        break;

                    case ServerSocketBelongTo.RTR:
                        rtrList.Remove(arg3);
                        break;

                    case ServerSocketBelongTo.Close:
                        break;

                    default:
                        throw new ArgumentException();
                    }
                    arg3.BelongTo = arg2;
                    OnUserCountChanged();
                    return;
                }

                //give up
                return;
            }
        }
예제 #2
0
        void AcceptCallback(IAsyncResult ar)
        {
            Socket s      = (Socket)ar.AsyncState;
            var    client = s.EndAccept(ar);
            var    cache  = new ServerSocketItem(client, System.Guid.NewGuid().ToString());

            cache.StatusChanged += client_StatusChanged;
            ConsoleAssistance.WriteLine($"[Socket] Accept {cache.EndPoint}'s connection and its Guid is {cache.Guid}.");
            ConsoleAssistance.WriteLine($"[Socket] {cache.Guid} starts to handshake...");

            cache.TimeClips = 3;
            handshakeList.Add(cache.Guid, cache);
            cache.BelongTo = ServerSocketBelongTo.Handshake;
            OnUserCountChanged();

            //accept next
            s.BeginAccept(new AsyncCallback(AcceptCallback), s);
        }