title: EOFError: ran out of input. Getting this error when trying to pickle.loads from a socket
body: <p>I have a <code>numpy ndarray</code> that I'm trying to send via socket connection. When I try to load it on the server, using <code>pickle.loads</code> I get <code>EOFError: ran out of input</code>. </p>
  
  <h1>client.py</h1>
  
  <pre><code>import numpy as np
  import socket, pickle
  import struct
  HOST = "192.168.143.xxx"
  PORT = 50007
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((HOST, PORT))
  centers = np.zeros((100, 43919))
  packet = pickle.dumps(centers)
  length = struct.pack('&gt;I', len(packet))
  packet = length + packet
  s.send(packet)
  
  data = s.recv(8192)
  data_new = pickle.loads(data)
  s.close()
  print ('Received', data_new)
  </code></pre>
  
  <h1>server.py</h1>
  
  <pre><code>import socket, pickle, numpy as np
  import struct
  HOST = ''
  PORT = 50007
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((HOST, PORT))
  s.listen(2)
  
  while 1:
      L = np.zeros((100, 43919))
      #wait to accept a connection - blocking call
      conn, addr = s.accept()
      print ('Connected with ', addr)
      buf = b''
      while len(buf) &lt; 4:
          buf += conn.recv(4 - len(buf))
  
      length = struct.unpack('&gt;I', buf)[0]
      print(length)
      data = conn.recv(length)
      if not data: break
      M = pickle.loads(data) # HERE IS AN ERROR, the same as np.loads(...)
      L += M
      data_out = pickle.dumps(L)
      conn.sendall(data_out)
      conn.close()
  
  s.close()
  </code></pre>
  
  <p>I've tried reading <a href="https://stackoverflow.com/questions/24726495/pickle-eoferror-ran-out-of-input-when-recv-from-a-socket">this</a>, <a href="https://stackoverflow.com/questions/24791987/why-do-i-get-pickle-eoferror-ran-out-of-input-with-my-python-script">this</a> and <a href="https://stackoverflow.com/questions/23983082/eoferror-ran-out-of-input-keep-getting-this-error-while-trying-to-pickle">this</a> but nothing helps.</p>
  
  <p>I'm using Python 3.4.</p>
  
  <p>EDIT:</p>
  
  <p>The exact error is:</p>
  
  <pre><code>File server.py, line 30, in &lt;module&gt;:
  M = pickle.loads(data) #HERE IS AN ERROR
  EOFError: Ran out of input.
  </code></pre>