JsonPikle to send Ryu object type

26 views
Skip to first unread message

abdullah...@gmail.com

unread,
May 14, 2018, 12:33:03 PM5/14/18
to jsonpickle

Dear,
I am not sure if this list is the right place to ask my question.
Actually, I am using Python to investigate my work in SDN using Ryu Controller.

Obviously, I have two python applications.
the first one sends object using socket to the second.
The object type is <class 'ryu.ofproto.ofproto_v1_3_parser.OFPPacketIn'>.

I have used pickle and json, but they could not send it.

I am trying Jsonpickle right now which send it well

def sendToC2(self, y):

        data = jsonpickle.encode(y)

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        host = socket.gethostname() # Get local machine name

       port = 12345                # Reserve a port for your service.

        s.connect((host, port))

        s.sendall(data)

        #print s.recv(1024)

        s.close

     
But the second application cannot decode it.

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

#host = socket.gethostname() # Get local machine name

port = 12345                # Reserve a port for your service.

s.bind(('', port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.

c, addr = s.accept()     # Establish connection with client.

while True:

                  x = c.recv(2048)

                  print 'Got connection from', addr

                  rdata =jsonpickle.decode(x)

                  if not rdata:

                      break

                  print 'the pakt is:', rdata

Traceback (most recent call last):

  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner

    self.run()

  File "/usr/lib/python2.7/threading.py", line 763, in run

    self.__target(*self.__args, **self.__kwargs)

  File "/home/mininet/ryu/ryu/app/C1.py", line 197, in foo

    rdata =jsonpickle.decode(x)

  File "/usr/local/lib/python2.7/dist-packages/jsonpickle/__init__.py", line 155                                                                                                 , in decode

    return unpickler.decode(string, backend=backend, keys=keys, classes=classes)

  File "/usr/local/lib/python2.7/dist-packages/jsonpickle/unpickler.py", line 26                                                                                                 , in decode

    return context.restore(backend.decode(string), reset=reset, classes=classes)

  File "/usr/local/lib/python2.7/dist-packages/jsonpickle/backend.py", line 197,                                                                                                  in decode

    raise e

ValueError: Unterminated string starting at: line 1 column 2028 (char 2027)


Could you help me
Best
A.Soliman

David Aguilar

unread,
May 15, 2018, 2:08:59 AM5/15/18
to jsonpickle
> ValueError: Unterminated string starting at: line 1 column 2028 (char 2027)
>
> Could you help me
> Best
> A.Soliman

I would suggest debugging this without the networking part.

This error looks like you're only reading 2048 bytes at a time, and
trying to decode that.

It really looks like the string is longer than that, and thus you're
trying to decode a partial / malformed string.

That's not going to work. You'll have to accumulate the complete
string on the receiving side before trying to decode it.
--
David
Reply all
Reply to author
Forward
0 new messages