0

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

shravani
  • 11
  • 4
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 14 '22 at 01:07
  • Have a look at the pynfs test suit http://git.linux-nfs.org/?p=bfields/pynfs.git;a=tree – kofemann Jun 15 '22 at 17:43
  • @kofemann Thank you. I will try this one. does this python client works with my server which is implemented in c? I want to use udp communication for client-server application, – shravani Jun 16 '22 at 13:42
  • That test suit has been used to test servers written in C, Java and C++. In general, as sunrpc uses xdr, it platform and programming language independent. – kofemann Jun 16 '22 at 15:26
  • Hi @kofemann, I checked your repo. you did a great job. As I am new in the RPC programming I have some doubts. Actually I need to create one sunrpc client in python which will send commands to the sunrpc server which is implemented in c. Using your xdrgen module I can create packer and unpackers of my .x file. I am confused how can I create client. I don't want to use nfs. forgive me If I am asking anything silly, as I don't have much knowledge on this. – shravani Jun 20 '22 at 08:22
  • https://github.com/astrand/pynfs/tree/master/ I am referring to this repo earlier. I was trying to run /demo/tempquery. but not able to run due to attribute errors. Can you please guide? – shravani Jun 20 '22 at 09:18

0 Answers0