How to send a list through TCP sockets - Python

前端 未结 2 1480
深忆病人
深忆病人 2021-02-06 13:24

I want to send a list through TCP sockets but i can\'t get the exact list when receiving from the server-side . To be more specific say that i have this list:

 y         


        
2条回答
  •  心在旅途
    2021-02-06 13:37

    Use pickle or json to send list(or any other object for that matter) over sockets depending on the receiving side. You don't need json in this case as your receiving host is using python.

    import pickle
    y=[0,12,6,8,3,2,10] 
    data=pickle.dumps(y)
    s.send(data)
    

    Use pickle.loads(recvd_data) on the receiving side.

    Reference: https://docs.python.org/2/library/pickle.html

提交回复
热议问题