Ejemplo n.º 1
0
        /// <summary>
        /// 서버 연결
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="tcpSession">The TCP session.</param>
        /// <returns></returns>
        public bool Connect(String host, int port, IProtocolResolver protocol_resolver, TCPSession tcpSession = null)
        {
            this.mEndPoint = new IPEndPoint(IPAddress.Parse(host), port);
            this.mSocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            if (tcpSession == null)
            {
                tcpSession = new TCPSession();
            }

            tcpSession.SetProtocolResolver(protocol_resolver);

            SocketAsyncEventArgs event_arg = new SocketAsyncEventArgs();

            event_arg.Completed     += OnConnect;
            event_arg.RemoteEndPoint = mEndPoint;
            event_arg.UserToken      = tcpSession;
            bool pending = mSocket.ConnectAsync(event_arg);

            if (false == pending)
            {
                OnConnect(null, event_arg);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public ClientSession(TCPSession tcpSession, NetworkSyncQueue networkSyncQueue, IProtocolResolver protocolResolver)
        {
            this.mTcpNetworkQueue = new WeakReference(networkSyncQueue);
            this.mTcpSession      = tcpSession;

            mTcpSession.SetClientSession(this);
            mTcpSession.SetProtocolResolver(protocolResolver);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when [receive completed].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SocketAsyncEventArgs"/> instance containing the event data.</param>
        public void OnReceiveCompleted(object sender, SocketAsyncEventArgs e)
        {
            TCPSession tcpSession = e.UserToken as TCPSession;

            if (e.LastOperation == SocketAsyncOperation.Receive)
            {
                tcpSession.OnReceive();
                return;
            }
            else
            {
                tcpSession.OnDisconnect();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when [connect].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SocketAsyncEventArgs"/> instance containing the event data.</param>
        private void OnConnect(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                TCPSession tcpSession = e.UserToken as TCPSession;
                tcpSession.OnConnectCompleted(mSocket);

                if (this.mConnectedCallback != null)
                {
                    this.mConnectedCallback(tcpSession);
                }

                tcpSession.OnConnect();
                tcpSession.ReceiveRequest();
            }
            else
            {
                // 연결 끊김
                if (this.mConnectedFailCallback != null)
                {
                    this.mConnectedFailCallback();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when [send completed].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SocketAsyncEventArgs"/> instance containing the event data.</param>
        public void OnSendCompleted(object sender, SocketAsyncEventArgs e)
        {
            TCPSession tcpSession = e.UserToken as TCPSession;

            tcpSession.OnSend();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 재연결
 /// </summary>
 /// <param name="tcp_session">The tcp_session.</param>
 public void OnReconnectComplete(TCPSession tcpSession)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 연결 완료
 /// </summary>
 /// <param name="tcp_session">The tcp_session.</param>
 public void OnConnnectComplete(TCPSession tcpSession)
 {
     mNetworkSyncQueue = new NetworkSyncQueue();
     mClientSession    = new ClientSession(tcpSession, mNetworkSyncQueue, mProtocolResolver);
 }