title: socket trouble in python
body: <p>I have a server that's written in C, and I want to write a client in python. The python client will send a string "send some_file" when it wants to send a file, followed by the file's contents, and the string "end some_file". Here is my client code :</p>
  
  <pre><code>
  file = sys.argv[1]
  host = sys.argv[2]
  port = int(sys.argv[3])
  sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  sock.connect((host,port))
  send_str = "send %s" % file
  end_str = "end %s" % file
  sock.send(send_str)
  sock.send("\n")
  sock.send(open(file).read())
  sock.send("\n")
  sock.send(end_str)
  sock.send("\n")
  </code></pre>
  
  <p>The problem is this :</p>
  
  <ul>
  <li><p>the server receives the "send some_file" string from a recv</p></li>
  <li><p>at the second recv, the file's content and the "end file" strings are sent together</p></li>
  </ul>
  
  <p>In the server code, the buffer's size is 4096. I first noticed this bug when trying to send a file that's less than 4096k.
  How can I make sure that the server receives the strings independently?</p>