title: socket.accept() in python; How to set client side for the connection port
body: <p>Instead on posting my mile long script here is a short example: I am creating a TCP/IP connection between two computers each running one of the following scripts:</p>
  
  <p>server:</p>
  
  <pre><code># server.py
  import socket
  
  s = socket.socket()
  host = socket.gethostname()
  port = 1234
  s.bind((host, port))
  
  s.listen(5)
  
  while True:
      c, addr = s.accept()
      print 'Connection from', addr
      c.close()
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>#client.py
  import socket
  
  s = socket.socket()
  
  host = socket.socket()
  port = 1234
  
  s.connect((host, port))
  print s.recv(1024)
  </code></pre>
  
  <p>which gives me a ready out like:</p>
  
  <pre><code>Connection from ('19*.1**.0.**', 54451)
  Connection from ('19*.1**.0.**', 54452)
  Connection from ('19*.1**.0.**', 54453)
  Connection from ('19*.1**.0.**', 54454)
  </code></pre>
  
  <p>What is controlling the creation of the 54451-54454 numbers? I understand what it is; the port number assigned to the client side connection. I just cant seem to figure out how to control the number, or at least the range its issued in. </p>
  
  <p>Is this even possible? Any suggestions would help immensely. Thank you in advance.</p>