title: python - socket not receiving data
body: <p>I am trying to implement a RFC1350 on top of a UDP. So far all was smooth sending a file
  from server to client worked like a charm i gave the method for receiving data to server and sending data to client but this direction is a no go.</p>
  
  <p>Key Server code:</p>
  
  <pre><code>    def listen(self):
      while True:
          packet, address = self.serverSocket.recvfrom(512)
  
          mode = str(packet)[2:5]
          self.file = str(str(packet)[6:]).replace("'", "")
  
          if(mode == "RRQ"):
              self.sendResponse(address)
          else:
              self.receiveData()
  
  def receiveData(self):
      data = open("new1.jpg", "wb")
      while True:
          packet, server = self.serverSocket.recvfrom(512)
          if packet.__len__() == 512:
              data.write(packet)
          else:
              data.write(packet)
              break;
  </code></pre>
  
  <p>Key Client code:</p>
  
  <pre><code>    def sendWRQ(self):
      request = 'WRQ-' + self.file
      self.clientSocket.sendto(str(request).encode(), (self.serverAddress, self.serverPort))
      self.sendData()
  
  def sendData(self):
      with open(self.file, "rb") as data:
          while True:
              packet = data.read(512)
              if packet != b"":
                  self.clientSocket.sendto(packet, (self.serverAddress, self.serverPort))
              else:
                  self.clientSocket.sendto(packet, (self.serverAddress, self.serverPort))
                  break
              time.sleep(0.0005)
  </code></pre>
  
  <ol>
  <li>Client sends WRQ packet whit a name of a file that will be the key of transfer</li>
  <li>Server recog. the transfer type RRQ or WRQ in this instance and starts listening for
  transfer via receiveData().</li>
  </ol>
  
  <p>Client terminates after sending sendWRQ() now a problem occurs on either Server or Client side in sendData or receiveData i get a file whit 0kB</p>
  
  <p>All of the code:</p>
  
  <ul>
  <li>Server Class: <a href="http://www.copypastecode.com/181330/" rel="nofollow">http://www.copypastecode.com/181330/</a></li>
  <li>Client Class: <a href="http://www.copypastecode.com/181326/" rel="nofollow">http://www.copypastecode.com/181326/</a></li>
  </ul>