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


C# Sockets.ExSocket類代碼示例

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


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

示例1: CloseHandshake

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="reason"></param>
 public override void CloseHandshake(ExSocket socket, string reason)
 {
     Dispose(socket, OpCode.Close, reason);
 }
開發者ID:huangchenjun,項目名稱:Scut,代碼行數:9,代碼來源:ClientSocket.cs

示例2: GameSession

 private GameSession(Guid sid, ExSocket exSocket, Action<ExSocket, byte[], int, int> sendCallback)
     : this(sid, null)
 {
     InitSocket(exSocket, sendCallback);
     //添加_remoteAddress 設置,方便打印遠程地址  [3/25/2014 lsx]
     _remoteAddress = exSocket.RemoteEndPoint.ToString();
 }
開發者ID:87170360,項目名稱:Maximus,代碼行數:7,代碼來源:GameSession.cs

示例3: Recover

 /// <summary>
 /// Recover session
 /// </summary>
 /// <param name="session"></param>
 /// <param name="newSessionKey"></param>
 /// <param name="socket"></param>
 /// <param name="sendCallback"></param>
 /// <returns></returns>
 public static void Recover(GameSession session, Guid newSessionKey, ExSocket socket, Action<ExSocket, byte[], int, int> sendCallback)
 {
     var newSession = Get(newSessionKey);
     if (session != null &&
         newSession != null &&
         session != newSession)
     {
         session._exSocket = socket;
         session._sendCallback = sendCallback;
         GameSession temp;
         _globalSession.TryRemove(newSessionKey, out temp);
     }
 }
開發者ID:87170360,項目名稱:Maximus,代碼行數:21,代碼來源:GameSession.cs

示例4: PostSend

 /// <summary>
 /// Posts the send.
 /// </summary>
 /// <param name="socket">Socket.</param>
 /// <param name="data">Data.</param>
 /// <param name="offset">Offset.</param>
 /// <param name="count">Count.</param>
 public void PostSend(ExSocket socket, byte[] data, int offset, int count)
 {
     byte[] buffer = new byte[count + 4];
     Buffer.BlockCopy(BitConverter.GetBytes(count), 0, buffer, 0, 4);
     Buffer.BlockCopy(data, offset, buffer, 4, count);
     socket.Enqueue(buffer);
     if (socket.TrySetSendFlag())
     {
         try
         {
             TryDequeueAndPostSend(socket, null);
         }
         catch
         {
             socket.ResetSendFlag();
             throw;
         }
     }
 }
開發者ID:haiya,項目名稱:Scut,代碼行數:26,代碼來源:SocketListener.cs

示例5: ProcessAccept

        private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
        {
            PostAccept();

            if (acceptEventArgs.SocketError != SocketError.Success)
            {
                HandleBadAccept(acceptEventArgs);
                return;
            }

            SocketAsyncEventArgs ioEventArgs = this.ioEventArgsPool.Pop();
            ioEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
            acceptEventArgs.AcceptSocket = null;
            this.acceptEventArgsPool.Push(acceptEventArgs);
            var dataToken = (DataToken)ioEventArgs.UserToken;
            ioEventArgs.SetBuffer(dataToken.bufferOffset, socketSettings.BufferSize);
            var exSocket = new ExSocket(ioEventArgs.AcceptSocket);
            exSocket.LastAccessTime = DateTime.Now;
            dataToken.Socket = exSocket;

            AddClient(exSocket);

            try
            {
                OnConnected(new ConnectionEventArgs { Socket = exSocket });
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("OnConnected error:{0}", ex);
            }

            PostReceive(ioEventArgs);
        }
開發者ID:haiya,項目名稱:Scut,代碼行數:33,代碼來源:SocketListener.cs

示例6: SendMessage

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="message"></param>
 /// <param name="encoding"></param>
 /// <param name="callback"></param>
 public void SendMessage(ExSocket socket, string message, Encoding encoding, Action<SocketAsyncResult> callback)
 {
     byte[] buffer = encoding.GetBytes(message);
     SendMessage(socket, buffer, callback);
 }
開發者ID:GamesDesignArt,項目名稱:UniversalCommon,代碼行數:12,代碼來源:RequestHandler.cs

示例7: OnClosedStatus

 protected override void OnClosedStatus(ExSocket socket, int closeStatusCode)
 {
     Console.WriteLine("Receive client {0} close status code {1}.", socket.RemoteEndPoint, closeStatusCode);
 }
開發者ID:daneric,項目名稱:Scut-samples,代碼行數:4,代碼來源:MainClass.cs

示例8: PostSend

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="opCode"></param>
 /// <param name="data"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 public override async Task PostSend(ExSocket socket, sbyte opCode, byte[] data, int offset, int count)
 {
     await PostSend(socket, opCode, data, offset, count, result => { });
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:12,代碼來源:SocketListener.cs

示例9: TryDequeueAndPostSend

 private void TryDequeueAndPostSend(ExSocket socket, SocketAsyncEventArgs ioEventArgs)
 {
     bool isOwner = ioEventArgs == null;
     SocketAsyncResult result;
     if (socket.TryDequeue(out result))
     {
         if (ioEventArgs == null)
         {
             ioEventArgs = ioEventArgsPool.Pop();
             ioEventArgs.AcceptSocket = socket.WorkSocket;
         }
         DataToken dataToken = (DataToken)ioEventArgs.UserToken;
         dataToken.Socket = socket;
         dataToken.AsyncResult = result;
         dataToken.byteArrayForMessage = result.Data;
         dataToken.messageLength = result.Data.Length;
         try
         {
             PostSend(ioEventArgs);
         }
         catch (Exception ex)
         {
             dataToken.ResultCallback(ResultCode.Error, ex);
             if (isOwner)
                 ReleaseIOEventArgs(ioEventArgs);
             socket.ResetSendFlag();
         }
     }
     else
     {
         ReleaseIOEventArgs(ioEventArgs);
         socket.ResetSendFlag();
     }
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:34,代碼來源:SocketListener.cs

示例10: DoClosedStatus

 private void DoClosedStatus(ExSocket socket, int statusCode)
 {
     Action<ExSocket, int> handler = OnClosedStatus;
     if (handler != null) handler(socket, statusCode);
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:5,代碼來源:SocketListener.cs

示例11: ProcessAccept

        private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
        {
            try
            {
                Interlocked.Increment(ref _summaryStatus.TotalConnectCount);
                maxConnectionsEnforcer.WaitOne();

                if (acceptEventArgs.SocketError != SocketError.Success)
                {
                    Interlocked.Increment(ref _summaryStatus.RejectedConnectCount);
                    HandleBadAccept(acceptEventArgs);
                }
                else
                {
                    Interlocked.Increment(ref _summaryStatus.CurrentConnectCount);

                    SocketAsyncEventArgs ioEventArgs = this.ioEventArgsPool.Pop();
                    ioEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
                    var dataToken = (DataToken)ioEventArgs.UserToken;
                    ioEventArgs.SetBuffer(dataToken.bufferOffset, socketSettings.BufferSize);
                    var exSocket = new ExSocket(ioEventArgs.AcceptSocket);
                    exSocket.LastAccessTime = DateTime.Now;
                    dataToken.Socket = exSocket;
                    acceptEventArgs.AcceptSocket = null;

                    //release connect when socket has be closed.
                    ReleaseAccept(acceptEventArgs, false);
                    try
                    {
                        OnConnected(new ConnectionEventArgs { Socket = exSocket });
                    }
                    catch (Exception ex)
                    {
                        TraceLog.WriteError("OnConnected error:{0}", ex);
                    }
                    PostReceive(ioEventArgs);
                }

            }
            finally
            {
                PostAccept();
            }
        }
開發者ID:huangbenyu,項目名稱:Scut,代碼行數:44,代碼來源:SocketListener.cs

示例12: Dispose

        /// <summary>
        /// 
        /// </summary>
        /// <param name="exSocket"></param>
        /// <param name="opCode"></param>
        /// <param name="reason"></param>
        protected void Dispose(ExSocket exSocket, sbyte opCode, string reason)
        {
            try
            {
                var e = new SocketEventArgs()
                {
                    Socket = exSocket,
                    Source = new DataMeaage() { OpCode = opCode, Message = reason }
                };
                DoClosed(e);
                OnDisconnected(e);
                if (exSocket != null) exSocket.Close();
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Dispose connect of client error:{0}", ex);
            }

        }
開發者ID:huangchenjun,項目名稱:Scut,代碼行數:25,代碼來源:ClientSocket.cs

示例13: OnClosedStatus

        /// <summary>
        /// 
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="closeStatusCode"></param>
        protected virtual void OnClosedStatus(ExSocket socket, int closeStatusCode)
        {

        }
開發者ID:huangbenyu,項目名稱:Scut,代碼行數:9,代碼來源:GameWebSocketHost.cs

示例14: Pong

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 public override void Pong(ExSocket socket)
 {
     byte[] data = Encoding.UTF8.GetBytes("pong");
     PostSend(socket, OpCode.Pong, data, 0, data.Length).Wait();
 }
開發者ID:lvshiling,項目名稱:Scut,代碼行數:9,代碼來源:SocketListener.cs

示例15: SendCloseHandshake

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="opCode"></param>
 /// <param name="reason"></param>
 public virtual void SendCloseHandshake(ExSocket socket, sbyte opCode, string reason)
 {
     if (MessageProcessor != null)
     {
         byte[] data = MessageProcessor.CloseMessage(socket, opCode, reason);
         if (data != null) AppServer.SendAsync(socket, data, result => { });
     }
 }
開發者ID:GamesDesignArt,項目名稱:UniversalCommon,代碼行數:14,代碼來源:RequestHandler.cs


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