• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Sockets.ExSocket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ZyGames.Framework.RPC.Sockets.ExSocket的典型用法代码示例。如果您正苦于以下问题:C# ExSocket类的具体用法?C# ExSocket怎么用?C# ExSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExSocket类属于ZyGames.Framework.RPC.Sockets命名空间,在下文中一共展示了ExSocket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: CloseHandshake

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="reason"></param>
 public override void CloseHandshake(ExSocket socket, string reason)
 {
     requestHandler.SendCloseHandshake(socket, OpCode.Close, reason);
 }
开发者ID:lvshiling,项目名称:Scut,代码行数:9,代码来源:SocketListener.cs


示例17: SendAsync

 /// <summary>
 /// 
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="buffer"></param>
 /// <param name="callback"></param>
 internal protected override async Task<bool> SendAsync(ExSocket socket, byte[] buffer, Action<SocketAsyncResult> callback)
 {
     socket.Enqueue(buffer, callback);
     return await Task.Run(() =>
     {
         if (socket.TrySetSendFlag())
         {
             try
             {
                 TryDequeueAndPostSend(socket, null);
                 return true;
             }
             catch (Exception ex)
             {
                 socket.ResetSendFlag();
                 TraceLog.WriteError("SendAsync {0} error:{1}", socket.RemoteEndPoint, ex);
             }
         }
         return false;
     });
 }
开发者ID:lvshiling,项目名称:Scut,代码行数:27,代码来源:SocketListener.cs


示例18: CloseSocket

 /// <summary>
 /// Closes the socket.
 /// </summary>
 /// <param name="socket">Socket.</param>
 public void CloseSocket(ExSocket socket)
 {
     try
     {
         socket.WorkSocket.Shutdown(SocketShutdown.Both);
     }
     catch { }
     socket.WorkSocket.Close();
 }
开发者ID:haiya,项目名称:Scut,代码行数:13,代码来源:SocketListener.cs


示例19: BuildMessagePack

 public override byte[] BuildMessagePack(ExSocket exSocket, sbyte opCode, 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);
     return buffer;
 }
开发者ID:yunjoker,项目名称:Scut,代码行数:7,代码来源:MessageHandler.cs


示例20: AddClient

 private void AddClient(ExSocket socket)
 {
     lock (clientSockets)
     {
         clientSockets.Add(socket);
     }
 }
开发者ID:haiya,项目名称:Scut,代码行数:7,代码来源:SocketListener.cs



注:本文中的ZyGames.Framework.RPC.Sockets.ExSocket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Model.GameUser类代码示例发布时间:2022-05-26
下一篇:
C# Sockets.ConnectionEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap