技术开发 频道

C++/CLI程序进程之间的通讯

  如同服务端一样,客户端取得一个IP地址,把它与端口号绑定以生成一个IPEndPoint,并连接到服务端,而服务端在此之前一直处于阻塞监听模式。在每一个发送与接收操作之间,我们有意延迟三秒,以便观察程序的输出。以下是一个服务端程序使用端口2500时的输出:

Server listener blocking status is True New connection accepted Received values 42 and 69, sent result 111 Received values 66 and 71, sent result 137 Received values 7 and 93, sent result 100 Received values 43 and 65, sent result 108 Received values 45 and 3, sent result 48 Shutting down server
而以下是对应的客户端程序,在发送5对值之后的输出:
Sent values 42 and 69, received result 111 Sent values 66 and 71, received result 137 Sent values 7 and 93, received result 100 Sent values 43 and 65, received result 108 Sent values 45 and 3, received result 48 Notified server we're shutting down Shutting down client
套接字上的串行化
 
  前面所演示的服务端与客户端程序以简单的方式进行数值交换,如int,然而,程序很有可能也会需要发送与接收各种不同的用户自定义的对象类型,这就涉及到串行化。
 
  试想某些金融程序所涉及到的许多事务类型,如存款、转账、取款,每一种都与事务有关。在此,只需简单地设置好适当的串行化与反串行化机制,服务端就能处理多个客户端请求,并可返回这些事务的任意数量与任意组合。
0
相关文章