コード例 #1
0
        private IAppSession ProcessNewClient(Socket socket, SslProtocols security)
        {
            if (!_readWritePool.TryPop(out SocketAsyncEventArgsProxy result))
            {
                AppServer.AsyncRun(() => socket.Shutdown(SocketShutdown.Both));
                return(null);
            }

            ISocketSession socketSession = new AsyncSocketSession(socket, result);

            socketSession.InitializeSendingQueue(this.SendingQueuePool);

            socketSession.Initialize(null);

            socketSession.Start();


            //var session = CreateSession(socket, socketSession);


            //if (session == null)
            //{
            //    result.Reset();
            //    this._readWritePool.Push(result);
            //    AppServer.AsyncRun(() => socket.Shutdown(SocketShutdown.Both));
            //    return null;
            //}

            socketSession.Closed += SessionClosed;

            //var negotiateSession = socketSession as INegotiateSocketSession;

            //if (negotiateSession == null)
            //{
            //    if (RegisterSession(session))
            //    {
            //        AppServer.AsyncRun(() => socketSession.Start());
            //    }

            //    return session;
            //}

            //negotiateSession.NegotiateCompleted += OnSocketSessionNegotiateCompleted;
            //negotiateSession.Negotiate();

            NewClientAccepted(socket, socketSession);
            return(null);
        }
コード例 #2
0
        private void Server_NewClientAccepted(Socket client, ISocketSession session)
        {
            Console.WriteLine("----- new client ------------");
            AsyncSocketSession ass = session as AsyncSocketSession;

            ass.ExtObject = "F**k";

            ass.SetReceiveHandler(arg =>
            {
                Console.WriteLine("----- new receive ------------");
                string received = System.Text.Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred);
                Console.WriteLine(received);

                ass.Send(received);
            });
        }
コード例 #3
0
        private void Server_CloseClientConnect(ISocketSession session)
        {
            AsyncSocketSession ass = session as AsyncSocketSession;

            Console.WriteLine(ass.ExtObject);
        }