python的SUNRPC实施

发布于 2025-02-06 18:55:27 字数 2208 浏览 0 评论 0原文

并且SUNRPC服务器已经在C中实现。

我想使用XDRLIB库在Python中创建SUNRPC客户端, projects/stackless/trunk/demo/rpc/rpc.py“ rel =” nofollow noreferrer“> https://svn.python.org/projects/stackless/stackless/trunk/demo/rpc/rpc/rpc/rpc.py

给出超时错误以及无法解开无对象错误。

谁能指导我如何完成?

在Google上没有有关此信息的信息。

有人实施了这种类型的代码吗?

请帮忙..我现在像一个星期一样挣扎。

这是我的客户端代码:

    import rpc
    import rpc_new
    from tq_const import *
    from tq_type import *
    import tq_pack
    import socket
    import os
    
    class PartialTQClient:
        def __init__(self):
            pass
    
        def addpackers(self):
            self.packer = tq_pack.TQPacker(self)
            self.unpacker = tq_pack.TQUnpacker(self, '')
    
        def unpack_month_temperatures(self):
            return self.unpacker.unpack_array(self.unpacker.unpack_uint)
    
        def call(self, month):
            res = self.make_call(0, month, self.packer.pack_uint, self.unpack_month_temperatures)
            return res
    
    
    class UDPTQClient(PartialTQClient, rpc.RawUDPClient):
        def __init__(self, host):
            rpc.RawUDPClient.__init__(self, host, TQ_PROGRAM, TQ_VERSION, TQ_PORT)
            PartialTQClient.__init__(self)
    
    
    if __name__ == "__main__":
        tqcl = UDPTQClient("127.0.0.1")
        print(tqcl)
        res = tqcl.call(12)
        #print ("Got result", res)
Here is my server code:
import rpc
import rpc_new
from tq_const import *
from tq_type import *
import tq_pack
import socket
import os



class TQServer(rpc.UDPServer):
    print("Inside TQServer")
    def handle_0(self):

        print ("Got request")
        m = self.unpacker.unpack_uint()
        print ("Arguments was", m)

        self.turn_around()
        self.packer.pack_array([1, 2, 3], self.packer.pack_int)
        
        #res = PFresults(self, status=TRUE, phone="555-12345")
        #res.pack()


if __name__ == "__main__":
    s = TQServer("", TQ_PROGRAM, TQ_VERSION, TQ_PORT)
    print ("Service started...",s)
    try:
        print("Trying")
        s.loop()
    finally:
        print ("Service interrupted.")

当我在localhost上运行客户端和服务器时,我会收到以下错误:typeError:无法解开非通行的非类型对象

I wanted to create sunrpc client in python using xdrlib library and sunrpc server is already implemented in C. I have implemented one rpc client in python over udp by referencing following link:

https://svn.python.org/projects/stackless/trunk/Demo/rpc/rpc.py

It is giving timeout error as well as can not unpack none object error.

can anyone guide me on this how it can be done?

there is no information available on this on google.

has anyone implemented such type of code?

please help..I am struggling on this like a week now.

Here is my client code:

    import rpc
    import rpc_new
    from tq_const import *
    from tq_type import *
    import tq_pack
    import socket
    import os
    
    class PartialTQClient:
        def __init__(self):
            pass
    
        def addpackers(self):
            self.packer = tq_pack.TQPacker(self)
            self.unpacker = tq_pack.TQUnpacker(self, '')
    
        def unpack_month_temperatures(self):
            return self.unpacker.unpack_array(self.unpacker.unpack_uint)
    
        def call(self, month):
            res = self.make_call(0, month, self.packer.pack_uint, self.unpack_month_temperatures)
            return res
    
    
    class UDPTQClient(PartialTQClient, rpc.RawUDPClient):
        def __init__(self, host):
            rpc.RawUDPClient.__init__(self, host, TQ_PROGRAM, TQ_VERSION, TQ_PORT)
            PartialTQClient.__init__(self)
    
    
    if __name__ == "__main__":
        tqcl = UDPTQClient("127.0.0.1")
        print(tqcl)
        res = tqcl.call(12)
        #print ("Got result", res)
Here is my server code:
import rpc
import rpc_new
from tq_const import *
from tq_type import *
import tq_pack
import socket
import os



class TQServer(rpc.UDPServer):
    print("Inside TQServer")
    def handle_0(self):

        print ("Got request")
        m = self.unpacker.unpack_uint()
        print ("Arguments was", m)

        self.turn_around()
        self.packer.pack_array([1, 2, 3], self.packer.pack_int)
        
        #res = PFresults(self, status=TRUE, phone="555-12345")
        #res.pack()


if __name__ == "__main__":
    s = TQServer("", TQ_PROGRAM, TQ_VERSION, TQ_PORT)
    print ("Service started...",s)
    try:
        print("Trying")
        s.loop()
    finally:
        print ("Service interrupted.")

When I am running client and server on localhost I am getting following error: TypeError: cannot unpack non-iterable NoneType object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文