python - Sending multiple lists (list of lists) over a network -
Suppose i have two lists which are coordinate of x and y of the number. Now I want to send 2 lists through sockets to other computers on one network. Because I want to send the lists, I add lists to a list of lists and then send the data.
1.Is there, do I need to pickle them up?
2. From the receiver, how do I delete lists and store values in 2 different lists?
Example status is given below:
listx = [1,2,3] list = [4,5,6] list_to_send.append ( Listx) list_to_send.append (listy) print list_to_send = & gt; [[1,2,3], [4,5,6]]
Send list to receiver
Receiver at that time:
a = socket.recv (1024)
How to unlink and unlock lists now?
A better option would be some structure like JSON. Pickles are a good option, but from the box, it is not very safe (I will put a link about this soon, soon). I am also convinced that you have more questions about serializing / disassigning compared to TCP socket.
& gt; & Gt; & Gt; Import json & gt; & Gt; & Gt; List_to_send = []> & Gt; & Gt; Listx = [1,2,3]> gt; & Gt; & Gt; List = [4,5,6]> gt; & Gt; & Gt; List_to_send.append (listx) & gt; & Gt; & Gt; List_to_send.append (listy) & gt; & Gt; & Gt; Json.dumps (list_to_send) '[[1, 2, 3], [4, 5, 6]]' & gt; & Gt; & Gt; Msg = json.dumps (list_to_send) & gt; & Gt; & Gt; SendOverSocket (msg)
and toward the receiver:
& gt; & Gt; & Gt; Msg = Received Format Set () & gt; & Gt; & Gt; List_received = json.loads (msg)
I have omitted the implementation of the above socket-specific functions.
To answer your question now:
1.Is there a list, do I need to pickle them up?
Yes, any objects that you send to the wire will have to be serial. Pickle or JSONify, call it your
2. How do I delete the list in favor of the receiver and store the values in 2 different lists?
Use json.loads (..)
as the above, or pick a specific function. In the code above, the list_listed [0]
will be the first list, list_received [1]
will be the second list and so on ..
Comments
Post a Comment