基本于ESFramework 的客户端和服务端终于可以通迅了!感谢ZHUWEI提供如此好的框架!ESFramework 功能强大,模拟完成端口,性能优越,这点可以见作者BLOG。通过ESFramework 不仅学习到了网络知识,更学习到了编程思想,基于接口的开发,编写框架的思想。
     相信有很多人和我一样对ESFramework 感兴趣。我愿意把我对ESFramework 的理解与收获与大家一起分享。下载代码 https://files.cnblogs.com/mediar/im20060412.rar
 
    MessageHeader需要应该实现,这一点我与作者持不同的意见,我认为消息头比较功能简单,比较固定。对性能影响不是很大,可以放在框架里实现。

    另外还要自己实现的是ContractHelper,PassiveHelper,SingleMessageDealer
(客户端接收到消息时,通知程序)

    服务端初使化时,关健要初使化一个分派器TcpStreamDispatcher。消息的到达是通过TcpStreamDispatcher通知用户的。TcpStreamDispatcher中的TcpClientsController
使用AgileTcp中的ITcpClientsController接口。整个初使化过程比较复杂,觉得应该还可以再简化一下。
  

 1基于ESFramewok的 客户端和服务端通迅  ContractHelper mContractHelper = new Im.Contract.ContractHelper();
 2基于ESFramewok的 客户端和服务端通迅   EsbNetMessageHook mEsbNetMessageHook = new EsbNetMessageHook();
 3基于ESFramewok的 客户端和服务端通迅   mEsbNetMessageHook.ContractHelper = mContractHelper;
 4基于ESFramewok的 客户端和服务端通迅
 5基于ESFramewok的 客户端和服务端通迅   EsbRequestDealerFactory mEsbRequestDealerFactory = new EsbRequestDealerFactory();
 6基于ESFramewok的 客户端和服务端通迅   mEsbRequestDealerFactory.ContractHelper = mContractHelper;
 7基于ESFramewok的 客户端和服务端通迅
 8基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher = new TcpStreamDispatcher();
 9基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher.RequestDealerFactory = mEsbRequestDealerFactory;
10基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher.ContractHelper = mContractHelper;
11基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher.TcpClientsController = new AgileTcp();
12基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher.RequestRecieved += new CbackRequestRecieved(mTcpStreamDispatcher_RequestRecieved);
13基于ESFramewok的 客户端和服务端通迅
14基于ESFramewok的 客户端和服务端通迅
15基于ESFramewok的 客户端和服务端通迅   mTcpStreamDispatcher.NetMessageHook = mEsbNetMessageHook;
16基于ESFramewok的 客户端和服务端通迅
17基于ESFramewok的 客户端和服务端通迅   tcp = new AgileTcp();
18基于ESFramewok的 客户端和服务端通迅   tcp.ContractHelper = mContractHelper;
19基于ESFramewok的 客户端和服务端通迅
20基于ESFramewok的 客户端和服务端通迅   tcp.BufferPool = new ESFramework.Network.Tcp.SimpleBufferPool();
21基于ESFramewok的 客户端和服务端通迅   tcp.Dispatcher = mTcpStreamDispatcher;
22基于ESFramewok的 客户端和服务端通迅   tcp.Initialize();
23基于ESFramewok的 客户端和服务端通迅
24基于ESFramewok的 客户端和服务端通迅   tcp.SomeOneConnected += new ESFramework.CbSimpleInt(tcp_SomeOneConnected);
25基于ESFramewok的 客户端和服务端通迅   tcp.SomeOneDisConnected += new CallBackDisconnect(tcp_SomeOneDisConnected);
26基于ESFramewok的 客户端和服务端通迅

 


客户端关健要初使化一个能处理一班消息的接口。开始我的客户端接收不到数据,后来才发现,这接收消息并处理的功能需要自己去实现。客户端初使如下
 

 1基于ESFramewok的 客户端和服务端通迅EsbNetMessageHook    netMessageHook   = new EsbNetMessageHook() ;
 2基于ESFramewok的 客户端和服务端通迅   netMessageHook.ContractHelper=new Im.Contract.ContractHelper();
 3基于ESFramewok的 客户端和服务端通迅   
 4基于ESFramewok的 客户端和服务端通迅            SingleMessageDealer   mSingleMessageDealer =new SingleMessageDealer();
 5基于ESFramewok的 客户端和服务端通迅            mSingleMessageDealer.eP2PMessageHandle+=new P2PMessageHandle(P2PMessage) ;
 6基于ESFramewok的 客户端和服务端通迅   
 7基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent =new TcpServerAgent();
 8基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent.TcpPassiveHelper=(ITcpPassiveHelper)(new Im.Contract.ContractHelper());
 9基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent.TcpPassive.NetMessageHook=netMessageHook;
10基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent.PassiveHelper =new PassiveHelper();
11基于ESFramewok的 客户端和服务端通迅
12基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent.SingleMessageDealer=mSingleMessageDealer;
13基于ESFramewok的 客户端和服务端通迅      serverProxy.TcpServerAgent.Initialize();
14基于ESFramewok的 客户端和服务端通迅
15基于ESFramewok的 客户端和服务端通迅   serverProxy.ContractHelper=new Im.Contract.ContractHelper();
16基于ESFramewok的 客户端和服务端通迅
17基于ESFramewok的 客户端和服务端通迅   serverProxy.TcpServerAgent.DataLacked+=new CbDataLacked(TcpServerAgent_DataLacked);
18基于ESFramewok的 客户端和服务端通迅

 


目前使用的功能只是基本的通迅功能,还有许多要续继学习,如P2P,插件等。欢迎大家和我一起学习交流.我的MSN:rr.m@163.com

相关文章: