.net csharp高并发socket异步通信框架Bouyei.NetProviderFactory

应用/框架/微服务
编辑评级:
分享:

项目基本信息

开发协议 GPL
操作系统 Windows  Linux  OS X 
开发语言 C#
项目所有者 bouyeijiang
收录时间 2017-07-30

项目介绍

.net csharp 高并发 socket 异步通信框架,一切尽在 demo 中,例子:

 using NetProviderFactory;
    class Program
    {
        static void Main(string[] args)
        {
            int port = 13145;
            //服务端         
   NetServerProvider serverSocket = new NetServerProvider();
            //已经截取接收到的真实数据 
           serverSocket.ReceiveHanlder = new OnReceiveHandler((sToken, buffer) =>
            {
                Console.WriteLine("complate:from client[" + Encoding.UTF8.GetString(buffer));
                serverSocket.Send(sToken, Encoding.UTF8.GetBytes("hi" + DateTime.Now));
            });

            //直接返回缓冲区和接收到的偏移  
          serverSocket.ReceiveOffsetHanlder = new OnReceiveOffsetHandler((sToken, buffer, offset, cnt) =>
            {
                byte[] dst = new byte[cnt];
                Array.Copy(buffer, offset, dst, 0, cnt);
                Console.WriteLine("offset:from client[" + Encoding.UTF8.GetString(dst));
            });

            bool isOk=serverSocket.Start(port);
            if (isOk)
            {
                Console.WriteLine("已启动服务。。。");

                //客户端     
           NetClientProvider clientSocket = new NetClientProvider();
                clientSocket.ReceiveHanlder = new OnReceiveHandler((sToken, buffer) =>
                {
                    Console.WriteLine("client:from server[" + Encoding.UTF8.GetString(buffer));
                });
                clientSocket.Connect(port, "127.0.0.1");
                System.Threading.Thread.Sleep(1000);
                clientSocket.Send(Encoding.UTF8.GetBytes("hello" + DateTime.Now));
            }
            Console.ReadKey();
        }
    }

同类项目推荐

相似项目推荐

bouyeijiang的其他项目

相关教程