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>Seems like you haven't implemented TCP in Java before.</p>

<p>The example you are providing with, uses a default <code>AF_INET</code> and <code>SOCK_STREAM</code> which <em>by default</em> is TCP:</p>

<blockquote>
  <p>socket.socket([family[, type[, proto]]])
  Create a new socket using the given address family, socket type and protocol number. The address family should be AF_INET (the default), AF_INET6 or AF_UNIX. The socket type should be SOCK_STREAM (the default), SOCK_DGRAM or perhaps one of the other SOCK_ constants. The protocol number is usually zero and may be omitted in that case.</p>
</blockquote>

<p>If you were implemented <code>SOCK_DGRAM</code> which is UDP, you wouldn't need to be using <code>sock.accept()</code></p>

java python sockets