免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1767 | 回复: 0
打印 上一主题 下一主题

server.py 代码分析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-08 22:50 |只看该作者 |倒序浏览

import sys, traceback, Ice
import Demo
class PrinterI(Demo.Printer):
    def printString(self, s, current=None):
        print s
status = 0
ic = None
try:
    ic = Ice.initialize(sys.argv)
    adapter = ic.createObjectAdapterWithEndpoints(
        "SimplePrinterAdapter", "default -p 10000")
    object = PrinterI()
    adapter.add(object, Ice.stringToIdentity("SimplePrinter"))
    adapter.activate()
    ic.waitForShutdown()
except:
    traceback.print_exc()
    status = 1
if ic:
    # Clean up
    try:
        ic.destroy()
    except:
        traceback.print_exc()
        status = 1
sys.exit(status)

这段代码包含以下步骤:
1. 调用 Ice.initialize初始化Ice run time(args是服务器可能需要的命令行参数).
调用结果ic是一个Ice.Communicator对象引用,这个引用是Ice run time的主句柄.
2. 我们调用adapter = ic.createObjectAdapterWithEndpoints,创建一个对象适配器.
传入参数:
    "SimplePrinterAdapter": 适配器的名字
    "default-p10000",     : 适配器使用缺省协议(TCP/IP)监听端口10000

3. 然后通过实例化接口PrinterI()为其创建一个"人"(servant)

4. adapter.add(object, Ice.stringToIdentity("SimplePrinter"))
   在适配器中添加佣人及其(佣人)字符串标识

5. 激活适配器.(适配器创建后处于保持状态)

6. 等待关闭

-----问题--------
adapter 和 servant 的具体含义, 最好举出实际例子
是否服务器通过adapter管理多个servant,比如多个打印机,但有什么意义呢?
客户端仍然需要知道具体的servant标识

看来我对运行原理还是毫无理解



   



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/13779/showart_212372.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP