0

I have a problem using sockets and pickle. I have a server send the same message to client in a hostname called for example server1. If I connected a client in the same machine I don't have any problem. But if I connect other machine remotely to this hostname, I have this problem when do

msg = sock.recv(16384)
tick_dict = pickle.loads(msg)
data_handler.update_dataframes(tick_dict)

I have ran simultaneously several localhost clients without problems, but if is remotely sometines I get the error: "_pickle.UnpicklingError: pickle data was truncated"

I have check the size message and never is bigger than 16384 bytes. What is happening?

Thanks!!

jatorna
  • 137
  • 6
  • 1
    ``sock.recv(n)`` reads *at most* ``n`` bytes and has no concept of messages. It does not guarantee that it reads an entire ``n`` sized "message" that was sent. You have to manually check whether you got all data you expected and keep receiving otherwise. See the [Socket Programming HowTO](https://docs.python.org/3/howto/sockets.html) for building message based protocols over TCP. – MisterMiyagi May 19 '20 at 13:13
  • 1
    https://stackoverflow.com/questions/1849523/is-pickle-file-of-python-cross-platform Pls refer to this question and see whether the pickle on remotehost and localhost are in terms. Mainly Pickle version and pickle format you are using.. few formats are not cross platform compatible – m0hithreddy May 19 '20 at 21:23
  • 1
    And pls provide your server code. – m0hithreddy May 19 '20 at 21:24
  • 1
    Since sock.recv results in partial reads by no means you can guarantee that all data is transferred in one call even if message size is less than 16384 as you claim. you need a while block to make sure everything is read. – m0hithreddy May 19 '20 at 21:45

0 Answers0