ice文件:
module Modipplace {
interface Ipplace{
string iptoplace(string s);
};
};
server文件:
ipplace_interface(ip):
省略
class IpplaceI(Modipplace.Ipplace):
def iptoplace(self,ip,current=None):
result = ipplace_interface(ip)
return result
if __name__ == "__main__":
reload(sys)
sys.setdefaultencoding("utf-8")
status = 0
ic = None
try:
ic = Ice.initialize(sys.argv)
adapter = ic.createObjectAdapterWithEndpoints("ipplaceAdapter", "tcp -p 5100")
object = IpplaceI()
adapter.add(object,ic.stringToIdentity("simpleIpplace"))
adapter.activate()
print "ice actuvated"
ic.waitForShutdown()
except:
traceback.print_exc()
status = 1
if ic:
# Clean up
try:
ic.destroy()
except:
traceback.print_exc()
status = 1
sys.exit(status)
client文件:
import sys,Ice
import Modipplace
if( len(sys.argv)!=2 ):
print "error , the usage is : ",sys.argv[0]," ip address"
exit(1)
ic=Ice.initialize(sys.argv)
base=ic.stringToProxy("simpleIpplace:tcp -p 5100")
ipplacer=Modipplace.IpplacePrx.checkedCast(base)
if not ipplacer:
raise RuntimeError("Invalid proxy")
print sys.argv[1],type(sys.argv[1])
place = ipplacer.iptoplace(sys.argv[1])
print "place: ",place
问题;这个是同步的情况,异步的情况很难写阿
参考:
两个简单的示例