Example #1
0
        internal IFuture Start()
        {
            lock (_rootSync)
            {
                if (_session != null && (_session.IsOpened ||
                                         _session.SessionState == SessionState.Opening))
                {
                    return(null);
                }

                if (_session != null)
                {
                    _session.Close();
                    _session = null;
                }

                if (_session == null)
                {
                    _session = new AsyncTcpSession(_remoteEP, true, 5000, 10000, true);
                    _session.PacketEncoder    = new DefaultPacketEncoder(_messageBodyEncoder);
                    _session.PacketDecoder    = new DefaultPacketDecoder(_messageBodyDecoder);
                    _session.ObjectReceived  += SessionObjectReceived;
                    _session.ExceptionCaught += SessionExceptionCaught;
                    _session.StateChanged    += SessionStateChanged;
                    _session.Closed          += SessionClosed;
                }

                return(_session.Open());
            }
        }
Example #2
0
        void OpenClinet(AsyncTcpSession tcpClient, int id)
        {
            AppendInfo(string.Concat("TcpClient:", id.ToString(), ", 开始连接服务器!"));
            AsyncFuture openFuture = tcpClient.Open() as AsyncFuture;

            openFuture.FutureCompleted += OpenFutureCompleted;
        }