1

I am trying to sent a list that contains both integer values as well as string values to a remote computer via socket communication. I tried converting the list to a bytearray that can then be sent using socket.send(), but I am receiving the following error:

TypeError: 'str' object cannot be interpreted as an integer

is there a way to send this information without splitting the integer and string parts of the list?

edit*: the code looks as following:

list=[1,"a"]

HOST= '192.168.0.31' # Server IP or Hostname
PORT = 12345 # Pick an open Port (1000+ recommended), must match the server port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST,PORT))
s.send(list)
m0hithreddy
  • 1,752
  • 1
  • 10
  • 17
Yes
  • 339
  • 3
  • 19

1 Answers1

1

From an answer to this question. Is pickle file of python cross-platform?

Since the pickel is cross-platform compatible (if certain conditions are met !) You can dump the pickel data into the socket of one machine, and read from the socket of the other machine. But you need to guarantee few things. It is better if the python versions running on the machines are same. And not all pickle formats are cross-platform compatible, but the default format ASCII pickles are compatible, Pls refer to the tagged question for more about pickle compatibility for cross platforms

And for the coding part

In server

s.sendall(pickle.dumps(list))

In the client side

list = pickle.loads(rcvd_data)
m0hithreddy
  • 1,752
  • 1
  • 10
  • 17