當前位置: 首頁>>代碼示例>>C#>>正文


C# Sockets.ConnectionEventArgs類代碼示例

本文整理匯總了C#中ZyGames.Framework.RPC.Sockets.ConnectionEventArgs的典型用法代碼示例。如果您正苦於以下問題:C# ConnectionEventArgs類的具體用法?C# ConnectionEventArgs怎麽用?C# ConnectionEventArgs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionEventArgs類屬於ZyGames.Framework.RPC.Sockets命名空間,在下文中一共展示了ConnectionEventArgs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnDataReceived

 private void OnDataReceived(ConnectionEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(this, e);
     }
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:7,代碼來源:SocketListener.cs

示例2: OnHandshaked

 private void OnHandshaked(ConnectionEventArgs e)
 {
     if (Handshaked != null)
     {
         Handshaked(this, e);
     }
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:7,代碼來源:SocketListener.cs

示例3: OnDisconnected

 private void OnDisconnected(ConnectionEventArgs e)
 {
     if (Disconnected != null)
     {
         Disconnected(this, e);
     }
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:7,代碼來源:SocketListener.cs

示例4: OnConnected

 private void OnConnected(ConnectionEventArgs e)
 {
     if (Connected != null)
     {
         Connected(this, e);
     }
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:7,代碼來源:SocketListener.cs

示例5: TryDecodePackage

        /// <summary>
        /// Decode request package
        /// </summary>
        /// <param name="e"></param>
        /// <param name="package"></param>
        /// <returns></returns>
        public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
        {
            package = null;
            string paramStr = Encoding.ASCII.GetString(e.Data);
            int index = paramStr.IndexOf("?d=", StringComparison.CurrentCultureIgnoreCase);
            string routeName = string.Empty;
            if (index != -1)
            {
                if (paramStr.StartsWith("route:", StringComparison.CurrentCultureIgnoreCase))
                {
                    routeName = paramStr.Substring(6, index - 6);
                }
                paramStr = paramStr.Substring(index, paramStr.Length - index);
                paramStr = HttpUtility.ParseQueryString(paramStr)["d"];
            }

            var nvc = HttpUtility.ParseQueryString(paramStr);
            var param = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var key in nvc.AllKeys)
            {
                param[key] = nvc[key];
            }
            if (param.ContainsKey("route"))
            {
                routeName = param["route"];
            }
            //if (!param.ContainsKey("ssid")) { Interlocked.Increment(ref errorDropNum); return; }
            if (!param.ContainsKey("actionid")) { return false; }
            if (!param.ContainsKey("msgid")) { return false; }

            //sessionId of proxy server
            Guid proxySid;
            if (!param.ContainsKey("ssid") || !Guid.TryParse(param["ssid"], out proxySid))
            {
                proxySid = Guid.Empty;
            }
            int actionid;
            if (!int.TryParse(param["actionid"], out actionid)) { return false; }
            int msgid;
            if (!int.TryParse(param["msgid"], out msgid)) { return false; }
            int userId;
            int.TryParse(param["uid"], out userId);

            string sessionId = param.ContainsKey("sid") ? param["sid"] : "";
            package = new RequestPackage(msgid, sessionId, actionid, userId)
            {
                ProxySid = proxySid,
                IsProxyRequest = param.ContainsKey("isproxy"),
                RouteName = routeName,
                IsUrlParam = true,
                UrlParam = paramStr
            };

            return true;
        }
開發者ID:kehaoran74,項目名稱:Scut,代碼行數:62,代碼來源:ActionDispatcher.cs

示例6: OnConnectCompleted

 protected override void OnConnectCompleted(object sender, ConnectionEventArgs e)
 {
     string address = e.Socket.RemoteEndPoint.ToString();
     if (!_sessions.ContainsKey(address))
     {
         var user = new GuestUser();
         user.Init();
         _sessions[address] = user;
     }
 }
開發者ID:Jachon,項目名稱:Scut,代碼行數:10,代碼來源:GameHostApp.cs

示例7: TryDecodePackage

        public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
        {
            //這裏解出頭部信息根據ActionId來分發請求到相應的Action子類
            package = null;
            byte[] content;
            MessagePack head = ReadMessageHead(e.Data, out content);
            if (head == null)
            {
                return false;
            }
            package = new RequestPackage(head.MsgId, head.SessionId, head.ActionId, head.UserId) { Message = content };

            return true;
        }
開發者ID:daneric,項目名稱:Scut-samples,代碼行數:14,代碼來源:CustomActionDispatcher.cs

示例8: TryDecodePackage

        public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
        {
            //這裏解出頭部信息根據ActionId來分發請求到相應的Action子類
            package = null;
            byte[] content;
            //todo test 1001 action
            //MessagePack packageHead = new MessagePack { MsgId = 1, ActionId = 1001, SessionId = "", UserId = 1380001 };
            //byte[] headBytes = ProtoBufUtils.Serialize(packageHead);
            //byte[] contentBytes = ProtoBufUtils.Serialize(new Request1001Pack() { PageIndex = 1, PageSize = 20 });
            //e.Data = BufferUtils.MergeBytes(BufferUtils.AppendHeadBytes(headBytes), contentBytes);

            MessagePack head = ReadMessageHead(e.Data, out content);
            if (head == null)
            {
            return false;
            }
            package = new RequestPackage(head.MsgId, head.SessionId, head.ActionId, head.UserId) { Message = content };

            return true;
        }
開發者ID:jinfei426,項目名稱:Scut,代碼行數:20,代碼來源:CustomActionDispatcher.cs

示例9: socketLintener_Disconnected

        void socketLintener_Disconnected(object sender, ConnectionEventArgs e)
        {
            try
            {
                ClientConnection clientConnection;
                if (clientConnections.TryGetValue(e.Socket, out clientConnection))
                {
                    clientConnections.Remove(clientConnection.SSID);
                    TraceLog.ReleaseWriteDebug("斷開 IP:{0},ssid:{1}", clientConnection.Socket.RemoteEndPoint, clientConnection.SSID);

                    if (clientConnection.ServerId != 0)
                    {
                        NameValueCollection requestParam = new NameValueCollection();
                        requestParam["actionid"] = ((int)ActionEnum.Interrupt).ToString();
                        requestParam["ssid"] = clientConnection.SSID.ToString("N");
                        requestParam["msgid"] = "0";
                        string paramStr = RequestParse.ToQueryString(requestParam);
                        byte[] paramData = Encoding.ASCII.GetBytes(paramStr);
                        try
                        {
                            gsConnectionManager.Send(clientConnection.GameId, clientConnection.ServerId, paramData);
                        }
                        catch (Exception ex)
                        {
                            TraceLog.WriteError("Send to tcp disconnected notify failed:{0}\r\nparam:{1}", ex, paramStr);
                        }
                    }
                }
                else
                {
                    TraceLog.ReleaseWriteDebug("斷開 IP:{0}。", e.Socket.RemoteEndPoint);
                }
            }
            catch (Exception err)
            {
                TraceLog.WriteError("Disconnected:{0}", err);
            }
        }
開發者ID:houguohua,項目名稱:Scut,代碼行數:38,代碼來源:SocketProxy.cs

示例10: socketLintener_DataReceived

 private void socketLintener_DataReceived(object sender, ConnectionEventArgs e)
 {
     try
     {
         Interlocked.Increment(ref receiveNum);
         OnReceivedBefore(e);
         RequestPackage package;
         if (!ActionDispatcher.TryDecodePackage(e, out package))
         {
             return;
         }
         var session = GetSession(e, package);
         if (CheckSpecialPackge(package, session))
         {
             return;
         }
         package.Session = session;
         package.ReceiveTime = DateTime.Now;
         requestQueue.Enqueue(package);
         singal.Set();
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Received to Host:{0} error:{1}", e.Socket.RemoteEndPoint, ex);
     }
 }
開發者ID:JohnnyXq,項目名稱:Scut,代碼行數:26,代碼來源:GameSocketHost.cs

示例11: socketLintener_Disconnected

 private void socketLintener_Disconnected(object sender, ConnectionEventArgs e)
 {
     try
     {
         GameSession session = GameSession.Get(e.Socket.HashCode);
         if (session != null)
         {
             OnDisconnected(session);
             session.ProxySid = Guid.Empty;
             session.Close();
         }
     }
     catch (Exception err)
     {
         TraceLog.WriteError("Disconnected error:{0}", err);
     }
 }
開發者ID:JohnnyXq,項目名稱:Scut,代碼行數:17,代碼來源:GameSocketHost.cs

示例12: OnReceivedBefore

 /// <summary>
 /// Raises the received before event.
 /// </summary>
 /// <param name="e">E.</param>
 protected virtual void OnReceivedBefore(ConnectionEventArgs e)
 {
 }
開發者ID:JohnnyXq,項目名稱:Scut,代碼行數:7,代碼來源:GameSocketHost.cs

示例13: GetSession

 private GameSession GetSession(ConnectionEventArgs e, RequestPackage package)
 {
     //使用代理分發器時,每個ssid建立一個遊服Serssion
     GameSession session;
     if (package.ProxySid != Guid.Empty)
     {
         session = GameSession.Get(package.ProxySid) ??
                   (package.IsProxyRequest
                       ? GameSession.Get(e.Socket.HashCode)
                       : GameSession.CreateNew(package.ProxySid, e.Socket, socketLintener.PostSend));
         if (session != null)
         {
             session.ProxySid = package.ProxySid;
         }
     }
     else
     {
         session = GameSession.Get(package.SessionId) ?? GameSession.Get(e.Socket.HashCode);
     }
     if (session != null && !session.Connected)
     {
         GameSession.Recover(session, e.Socket.HashCode, e.Socket, socketLintener.PostSend);
     }
     return session;
 }
開發者ID:JohnnyXq,項目名稱:Scut,代碼行數:25,代碼來源:GameSocketHost.cs

示例14: socketLintener_DataReceived

        void socketLintener_DataReceived(object sender, ConnectionEventArgs e)
        {
            var data = Encoding.ASCII.GetString(e.Data);
            try
            {

                string routeName = string.Empty;
                int index = data.LastIndexOf("?d=");
                if (index > 0)
                {
                    if (data.StartsWith("route:", StringComparison.CurrentCultureIgnoreCase))
                    {
                        routeName = data.Substring(6, index - 6);
                    }
                    data = data.Substring(index, data.Length - index);
                }
                data = HttpUtility.ParseQueryString(data)["d"];
                int gameId, serverId, statuscode;
                var ip = e.Socket.RemoteEndPoint.ToString().Split(new char[] { ':' })[0];
                var requestParam = RequestParse.Parse(ip, "", data, out gameId, out serverId, out statuscode);
                if (statuscode != (int)HttpStatusCode.OK)
                {// 接收到非法數據
                    listener.CloseSocket(e.Socket);
                    return;
                }
                ClientConnection clientConnection;
                if (!clientConnections.TryGetValue(e.Socket, out clientConnection))
                {
                    TraceLog.WriteError("接收到不在連接池中的socket數據,哪裏有bug。");
                    listener.CloseSocket(e.Socket);
                    return;
                }

                if (clientConnection.GameId == 0) clientConnection.GameId = gameId;
                if (clientConnection.ServerId == 0) clientConnection.ServerId = serverId;

                requestParam["UserHostAddress"] = ip;
                requestParam["ssid"] = clientConnection.SSID.ToString("N");
                requestParam["http"] = "0";
                string paramStr = string.Format("{0}&UserHostAddress={1}&ssid={2}&http=0",
                    data,
                    ip,
                    requestParam["ssid"]);
                if (!string.IsNullOrEmpty(routeName))
                {
                    requestParam["route"] = routeName;
                    paramStr += "&route=" + routeName;
                }
                byte[] paramData = Encoding.ASCII.GetBytes(paramStr);

                try
                {
                    if (!gsConnectionManager.Send(gameId, serverId, paramData))
                    {
                        var responseData = RequestParse.CtorErrMsg(10000, RequestParse.ErrorMsgConnectFail, requestParam);
                        SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
                    }
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("無法連接遊服error:{0}\r\nparam:{1}", ex, paramStr);
                    var responseData = RequestParse.CtorErrMsg(10000, RequestParse.ErrorMsgConnectFail, requestParam);
                    SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
                }
            }
            catch (Exception err)
            {
                TraceLog.WriteError("DataReceived error:{0},param:{1}", err, data);
            }
        }
開發者ID:houguohua,項目名稱:Scut,代碼行數:70,代碼來源:SocketProxy.cs

示例15: OnError

 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnError(ISocket sender, ConnectionEventArgs e)
 {
     sender.CloseHandshake(e.Socket, "param error");
 }
開發者ID:huangbenyu,項目名稱:Scut,代碼行數:9,代碼來源:GameWebSocketHost.cs


注:本文中的ZyGames.Framework.RPC.Sockets.ConnectionEventArgs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。