标签:
NetworkComms通信框架,是一款来自英国的c#语言编写的通信框架,历时6年研发,成熟稳定,性能可靠。
NetworkComms v3的核心功能在一定程度上是以异步的方式进行的。
NetworkComms提供了相应的功能,使得可以同步请求数据和获得相应的相应,非常的简单。
try { //连接信息类 ConnectionInfo connectionInfo = new ConnectionInfo("127.0.0.1", 10000); //获取一个TCP连接 TCPConnection serverConnection = TCPConnection.GetConnection(connectionInfo); //发送一个消息类型是“RequestCustomObject“的,数据类型为int,具体数值为 “1000”的数据给服务器,并获取消息类型为“CustomObjectReply",类型为CustomObject的数据 CustomObject myCustomObject = serverConnection.SendReceiveObject<CustomObject>("RequestCustomObject", "CustomObjectReply", 1000); } catch (ExpectedReturnTimeoutException) { }
服务器上对应的处理方法:
NetworkComms.AppendGlobalIncomingPacketHandler<int>("RequestCustomObject", (packetHeader, connection, input) => { //创建一个要返回的类型 CustomObject myCustomObject = new CustomObject(); //把要返回的类型,发送给客户端 connection.SendObject("CustomObjectReply", myCustomObject); });
原文:http://www.networkcomms.net/synchronous-send-and-receive/
www.networkcomms.cn整理
标签:
原文地址:http://www.cnblogs.com/networkcomms/p/4318694.html