科技时代新浪首页 > 科技时代 > 学园 > 正文

实例解析C++/CLI程序进程之间的通讯(3)


http://www.sina.com.cn 2006年05月10日 17:00 天极yesky

  套接字上的串行化

  前面所演示的服务端与客户端程序以简单的方式进行数值交换,如int,然而,程序很有可能也会需要发送与接收各种不同的用户自定义的对象类型,这就涉及到串行化。

  试想某些金融程序所涉及到的许多事务类型,如存款、转账、取款,每一种都与事务有关。在此,只需简单地设置好适当的串行化与反串行化机制,服务端就能处理多个客户端请求,并可返回这些事务的任意数量与任意组合。

  以下有一些练习来加深对此的了解:

  1、 如果一个服务端连接队列已满,那对新的客户端连接请求来说,会发生什么呢?

  2、 如果当客户端还有一个打开的套接字,而服务端此时却关闭了,会发生什么呢?反之呢?

  3、 试着运行一个服务端和两个客户端。我们前面说过,服务端只能处理一个客户端,为使服务端能同时处理多个客户端,需要进行多线程设计,建议对服务端作一些适当的修改,并用两个、三个、或更多客户端来测试。

  4、 以下是当有两个客户端运行时的输出:

Client 2600 4
Sent values 56 and 35, received result 91
Sent values 48 and 20, received result 68
Sent values 6 and 97, received result 103
Sent values 76 and 9, received result 85
Notified server we're shutting down
Shutting down client
Client 2600 2
Sent values 69 and 66, received result 135
Sent values 84 and 45, received result 129
Notified server we're shutting down
Shutting down client
Server 2600
Waiting for new connection request
New connection accepted
Started thread Thread-1
Waiting for new connection request
Executing thread Thread-1
Received values 56 and 35, sent result 91
New connection accepted
Started thread Thread-2
Waiting for new connection request
Executing thread Thread-2
Received values 69 and 66, sent result 135
Received values 48 and 20, sent result 68
Received values 84 and 45, sent result 129
Received values 6 and 97, sent result 103
Shutting down server thread Thread-2
Received values 76 and 9, sent result 85
Shutting down server thread Thread-1

[上一页] [1] [2] [3]

发表评论

爱问(iAsk.com) 相关网页共约54,800,000篇。



评论】【论坛】【收藏此页】【 】【多种方式看新闻】【下载点点通】【打印】【关闭




科技时代意见反馈留言板 电话:010-82628888-5595   欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

Copyright © 1996 - 2006 SINA Corporation, All Rights Reserved

新浪公司 版权所有