title: Convert C socket program to python
body: <p>I have been trying to convert this receiver code in C to python..
  The python code i have used doesn't seems to be receiving anything.. 
  The C code for sender uses</p>
  
  <pre><code>        sendto(sid,buffer,1023,0,(struct sockaddr *)&amp;saddr,sizeof(saddr));
  </code></pre>
  
  <p>What is the problem while converting the following code to python.</p>
  
  <pre><code>        #include&lt;stdio.h&gt;
          #include&lt;sys/types.h&gt;
          #include&lt;sys/socket.h&gt;
          #include&lt;netinet/in.h&gt;
          #include&lt;errno.h&gt;
          #include&lt;unistd.h&gt;
          #include&lt;stdlib.h&gt;
          int main(char *argv[])
          {
          socklen_t sid,clen;
          char buffer[1024];
          struct sockaddr_in saddr,caddr;
          int n;
          sid=socket(AF_INET,SOCK_DGRAM,0);
          if(sid&lt;0)
              perror("socket_create");
          bzero((char*)&amp;saddr,sizeof(saddr));
          saddr.sin_family=AF_INET;
          saddr.sin_port=htons(12346);
          saddr.sin_addr.s_addr=INADDR_ANY;
          if(bind(sid,(struct sockaddr *)&amp;saddr,sizeof(saddr))&lt;0)
              perror("socket_bind");
          while(1)
          {
          clen=sizeof(caddr);
          bzero(buffer,1024);
          n=recvfrom(sid,buffer,1023,0,(struct sockaddr*)&amp;caddr,&amp;clen);
          if(n&lt;0)
              perror("receive");
          printf("Array : %s\n", buffer);
          }
          close(sid);
          return 0;
          }
  </code></pre>
  
  <p>Python code i tried is</p>
  
  <pre><code>            import socket
              import sys
              from thread import *
  
              HOST = "127.0.0.1"   # Symbolic name meaning all available interfaces
              PORT = 12346 # Arbitrary non-privileged port
  
              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              print 'Socket created'
  
              #Bind socket to local host and port
              try:
                  s.bind((HOST, PORT))
              except socket.error , msg:
                  print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
                  sys.exit()
  
              print 'Socket bind complete'
  
              #Start listening on socket
              s.listen(10)
              print 'Socket now listening'
  
              #Function for handling connections. This will be used to create threads
              def clientthread(conn):
                  #Sending message to connected client
                  conn.send('Welcome to the server. Type something and hit enter\n') #send only takes string
  
                  #infinite loop so that function do not terminate and thread do not end.
                  while True:
  
                      #Receiving from client
                      data = conn.recv(1024)
                      reply = 'OK...' + data
                      if not data:
                          break
  
                      conn.sendall(reply)
  
                  #came out of loop
                  conn.close()
  
              #now keep talking with the client
              while 1:
                  #wait to accept a connection - blocking call
                  conn, addr = s.accept()
                  print 'Connected with ' + addr[0] + ':' + str(addr[1])
  
                  #start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
                  start_new_thread(clientthread ,(conn,))
  
              s.close()
  </code></pre>