Пример #1
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        public void Connect(string ip, int port)
        {
            //// 暂时先这样,以后修改为在外部处理 2015年12月23日 16:25:48
            //Close();

            mSession = mSocket.Connect(ip, port);
            mSession.SetHandleReceive(Receive);
            mSocket.ReceiveCompleted = OnReceive;
            mSession.mNetType = Net.ENet.UdpClient;

            if (Connected != null)
                Connected(Net.ENet.UdpClient, mSession);
        }
Пример #2
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="AdapterID">唯一值</param>
 /// <param name="net">网络模型</param>
 /// <param name="param">参数值</param>
 public override void Init(long lAdapterID, ENet net, object param)
 {
     base.Init(lAdapterID, net, param);
     mSession = param as UDPSession;
 }
Пример #3
0
        /// <summary>
        /// 接收到数据
        /// </summary>
        /// <param name="udpSession"></param>
        /// <param name="byData"></param>
        protected void OnReceive(IPEndPoint ipEndPoint, byte[] byData)
        {
            UDPSession udpSession;
            if (HasSession(ipEndPoint))
            {
                long lSessionID = GetSessionID(ipEndPoint);
                udpSession = GetSession(lSessionID);
            }
            else
            {
                udpSession = new UDPSession(mSocket, ipEndPoint);
                udpSession.SetHandleReceive(Receive);
                InsertSession(udpSession);
            }

            // 接收处理
            udpSession.Receive(byData);
        }
Пример #4
0
        protected void RemoveSession(UDPSession session)
        {
            lock (mSessionLock)
            {
                mSessionSet.Remove(session.GetIPEndPoint());

                if (session != null)
                    mSessionDict.Remove(session.SessionID);
            }
        }
Пример #5
0
        /// <summary>
        /// 插入Session
        /// </summary>
        /// <param name="session"></param>
        protected void InsertSession(UDPSession session)
        {
            lock (mSessionLock)
            {
                if (mSessionSet.ContainsKey(session.GetIPEndPoint()))
                    return;

                session.SessionID = NetSessionID();
                mSessionSet.Add(session.GetIPEndPoint(), session.SessionID);

                mSessionDict.Add(session.SessionID, session);

                session.mNetType = Net.ENet.UdpServer;
                if (Connected != null)
                    Connected(Net.ENet.UdpServer, session);
            }
        }