38 Star 127 Fork 39

koko / SiMaySockets

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md
  • 模式说明
  • Full模式:仅接收发送数据(高性能的数据接收模型,可启用TcpKeepAlive选项)注:数据压缩丶AppKeepAlive选项在Full模式下启用无效
  • Pack模式:自动处理分包(高性能的数据接收模型,自动处理分包,可启用数据压缩丶应用层心跳包丶TcpKeepAlive选项)
            //使用实例

            var serverConfig = new TcpSocketSaeaServerConfiguration();
            serverConfig.KeepAlive = true;
            server = TcpSocketsFactory.CreateServerAgent(TcpSocketSaeaSessionType.Full, serverConfig, Server_CompletetionNotify);


        private void Server_CompletetionNotify(TcpSocketCompletionNotify e, TcpSocketSaeaSession session)
        {
            this.Invoke(new Action(()=> {
                switch (e)
                {
                    case TcpSocketCompletionNotify.OnConnected:

                        //session初始化完成连接的事件
                        //调用session.SendAsync();对session发送消息
                        //调用session.Close(true)断开session连接,并通知断开事件
                        //可在session.AppTokens中绑定应用对象,以便在其他异步事件中调用

                        this.listBox1.Items.Add("successful client connection");

                        break;
                    case TcpSocketCompletionNotify.OnSend:

                        //session发送数据通知事件

                        //session.SendTransferredBytes == 以发送数据长度

                        break;
                    case TcpSocketCompletionNotify.OnDataReceiveing:

                        //session数据接收通知事件

                        //session.ReceiveBytesTransferred == 本次接收数据长度
                        //Packet模式下 session.CompletedBuffer.Length == 完整数据包长度

                        this.listBox1.Items.Add("len:" + session.CompletedBuffer.Length + " msg:" + Encoding.UTF8.GetString(session.CompletedBuffer, 0, session.ReceiveBytesTransferred));
                        break;
                    case TcpSocketCompletionNotify.OnDataReceived:

                        //Packet模式session自动处理分包的完成事件

                        //var pack = session.CompletedBuffer;//完整数据包
                        break;
                    case TcpSocketCompletionNotify.OnClosed:

                        //session断开通知事件

                        this.listBox1.Items.Add("server :client offline");
                        break;
                }
            }));
        }

Comments ( 23 )

Sign in for post a comment

About

可跨平台的轻量级高性能Socket库,基于IOCP / EPOLL通信模型,并结对象池等技术实现高效异步对象复用,实现了应用层心跳包检测,可满足一般应用快速开发,内部实现了高性能的数据处理器PULL丶全自动分包处理处理器PACK,欢迎大家点星星呀,项目不定时更新 spread retract
C#
MIT
Cancel

Releases

No release

Gitee Metrics

Contributors

All

Activities

load more
can not load any more
C#
1
https://gitee.com/dWwwang/SiMaySocket.git
git@gitee.com:dWwwang/SiMaySocket.git
dWwwang
SiMaySocket
SiMaySockets
master

Search

101046 36f486cf 1899542 101055 4cb66026 1899542