当前位置: 首页>>代码示例>>Python>>正文


Python Server.message方法代码示例

本文整理汇总了Python中jsonrpclib.Server.message方法的典型用法代码示例。如果您正苦于以下问题:Python Server.message方法的具体用法?Python Server.message怎么用?Python Server.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonrpclib.Server的用法示例。


在下文中一共展示了Server.message方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RVI

# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import message [as 别名]

#.........这里部分代码省略.........
        # Check if we have a thread going
        if self.serve_thread == False:
            self.start_serve_thread()
            
        full_service_name = res['service']
        self.registered_services[service_name] = full_service_name

        # Return the fully qualified service name
        return res['service']

    # Unregister a service 
    #  Unregisters a service previously registered with register_service
    #  The provided 'service_name' is identical to that provided tgo
    #  retister_service()
    #
    def unregister_service(self, service_name):

        if service_name[0] != '/':
            service_name = '/' + service_name

        # Check that the service has been previously registered
        # If not just return
        if service_name not in self.registered_services:
            return False
            

        # Retrieve the fully qualified service name that
        # we need to unregister from rvi
        full_service_name = self.registered_services[service_name]

        # Delete dictionary entry
        del self.registered_services[service_name]

        #
        # Unregister the service from RVI
        #
        res = self.rvi_client.unregister_service(service=full_service_name)
        
        return True

    def start_serve_thread(self):
        self.serve_thread = threading.Thread(target=self.serve_forever)
        self.serve_thread.start()

    #
    # Return the URL that we've setup for incoming JSON-RPC calls
    # from the RVI node.
    #
    def url(self):
        return 'http://' + self.rvi_address + ':' + str(self.rvi_port)
        
    
    #
    # Send a message to the RVI node to be forwarded to the
    # service that registered 'service_name' in the network.
    #
    def message(self, service_name, parameters, timeout = int(time.time()) + 60 ):
        self.rvi_client.message(service_name = service_name,
                                timeout = timeout,
                                parameters = parameters)
        

    #
    # Redefined shutdown method that first unregisters all services.
    #
    def shutdown(self):
        shutdown_list = self.registered_services.keys()
        for svc in shutdown_list:
            self.unregister_service(svc)

        SimpleJSONRPCServer.shutdown(self)

    #
    # Check if method is 'message', if so dispatch on
    # name 'service_name' instead.
    #
    def _dispatch(self, method, params):
        if method == 'message':
            # print "Will dispatch message to: " + params['service_name']
            dict_param = {}
            # Extract the 'parameters' element from the top level JSON-RPC
            # 'param'. 
            # Convert 'parameters' from [{'vin': 1234}, {hello: 'world'}] to
            # a regular dictionary: {'vin': 1234, hello: 'world'}

            # print "Parameters:", params['parameters']
            msg_params = params['parameters'] 
            for i in range(0, len(msg_params)):
                for j in range(0, len(msg_params[i].keys())):
                    # print "params", msg_params[i].keys()[j], "=", msg_params[i].values()[j]
                    dict_param[msg_params[i].keys()[j]] = msg_params[i].values()[j]

            # print "Parameter disctionary: ", dict_param
            # print 
            # Ship the processed dispatch info upward.
            return SimpleJSONRPCServer._dispatch(self, params['service_name'], dict_param)           

        # Fallthrough to all other methods.
        # Will handle service_re3
        return SimpleJSONRPCServer._dispatch(self,method, params)           
开发者ID:jochenschneider,项目名称:rvi_core,代码行数:104,代码来源:rvilib.py


注:本文中的jsonrpclib.Server.message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。