免费注册 查看新帖 |

Chinaunix

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

slice及其编译 [复制链接]

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


获得slice2py.exe后, 赶紧体验了一把 map to python
按照Ice3.1.1帮助文件 [3.7Writing an Ice Application with Python]
copy & paste printer.ice
在dos窗口下
F:\ICEstudy>slice2py printer.ice
生成一个Demo目录和printer_ice.py

生成的文件略感繁琐(比我事先想象的)
又按帮助 paste server.py和client.py,
然后先后运行server和client,一试就灵. 稍稍遗憾的就是代码有点不够好看,比如server.py
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)

----Icepy3.1.1
发现Icepy下的代码形式不错, 而且竟然不用slice2py.exe,早知如此我就不用费劲要它了
于是仿照改写了server.py
import sys, traceback, Ice
Ice.loadSlice('printer.ice')
import Demo
class PrinterI(Demo.Printer):
    def printString(self, s, current=None):
        print s
class Server(Ice.Application):
    def run(self, args):
       adapter = self.communicator().createObjectAdapter("SimplePrinterAdapter")
       adapter.add(PrinterI(), self.communicator().stringToIdentity("SimplePrinter"))
       adapter.activate()
       self.communicator().waitForShutdown()
       return True
app = Server()
sys.exit(app.main(sys.argv, "config.server"))

其中的配置参数都设置在config.server文件(保存于同目录)
#
# The server creates one single object adapter with the name
# "SimplePrinterAdapter". The following line sets the endpoints for this
# adapter.
#
SimplePrinterAdapter.Endpoints=tcp -p 10000:udp -p 10000
#
# Warn about connection exceptions
#
Ice.Warn.Connections=1
#
# We want a faster ACM for this demo.
#
Ice.ACM.Server=10
#
# Network Tracing
#
# 0 = no network tracing
# 1 = trace connection establishment and closure
# 2 = like 1, but more detailed
# 3 = like 2, but also trace data transfer
#
#Ice.Trace.Network=1
#
# Protocol Tracing
#
# 0 = no protocol tracing
# 1 = trace protocol messages
#
#Ice.Trace.Protocol=1


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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP