title: Python UDP client/server program, problems
body: <p>I'm trying to write a basic client/server echo program, to test the usage of timers for retransmission based on select() (though I had to comment out that bit to simplify debugging when it wasn't working as intended). Here are snippets of the relevant code:</p>
  
  <p>Server:</p>
  
  <pre><code>from socket import *
  import sys
  import select
  address = ('localhost', 6005)
  server_socket = socket(AF_INET, SOCK_DGRAM)
  server_socket.bind(address)
  
  while(1):
      print "Listening"
      recv_data, addr = server_socket.recvfrom(2048)
      print recv_data
      if recv_data == "Request 1" :
          print "Received request 1"
          server_socket.sendto("Response 1", address)
      elif recv_data == "Request 2" :
          print "Received request 2"
          data = "Response 2"
          server_socket.sendto(data, address)
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>from socket import *
  import sys
  import select
  
  address = ('localhost', 6005)
  client_socket = socket(AF_INET, SOCK_DGRAM)
  
  num_retransmits = 0
  while(num_retransmits &lt; 60):
      num_retransmits = num_retransmits + 1
  
  
      data = "Request 1"
      client_socket.sendto(data, address)
      print "Sending request 1"
  
      recv_data, addr = client_socket.recvfrom(2048)
  
      print recv_data, "!!"
  </code></pre>
  
  <p>The output on the client is simply 'Sending request 1', and when a breakpoint is used on anything at or below the recvfrom call, it does not reach the breakpoint. So I figure the client is not receiving anything and is holding out til it does. On the other hand, the output on the server is:</p>
  
  <ul>
  <li>Listening  </li>
  <li>Request 1  </li>
  <li>Received request 1</li>
  <li>Listening</li>
  <li>Response 1</li>
  </ul>
  
  <p>and so on and so forth</p>
  
  <p>After the first loop, the server loops again and prints RESPONSE 1. This means that what the server did was to receive request 1, send response 1 to the client, loop...  but after it loops the second time, response 1 is STILL in its socket! That is why when it prints recv_data,it prints response 1. On the other hand, client is not printing recv_data, because client has not received it - it is still in the buffer of the server's socket.</p>
  
  <p>Please help - I have tried looking at other echo programs but they all seem to use TCP and are fairly straightforward (and I think I have pretty much followed the same steps). I have no idea why my UDP program is not working. I tried looking at the sendall() call but it only seems to work for TCP.</p>