Why and how am i supposed to use socket.accept() in python?
<p>This <code>accept()</code> method return a tuple with a new socket and an address but why do i need a new socket if i already have one, so why don't use it?</p>

<pre><code>import socket
sock = socket.socket()
sock.bind(('', 9090))
sock.listen(1)
conn, addr = sock.accept()

print 'connected:', addr

while True:
    data = conn.recv(1024)
    if not data:
        break
   conn.send(data.upper())

conn.close()
</code></pre>

<p>ps: When i program sockets in Java, i don't really have this kind of <em>accepting</em> stuff and i only need one socket per client and one per server, which makes sense.</p>

<p>You have one listening socket active while the server is running and one new connected socket for each accepted connection which is active until the connection is closed.</p>

java python sockets