title: How to send and receive from the same socket in Python?
body: <p>I'm am trying to write a client program in Python that can send and receive from the same socket, but it is always giving me the same error which address is already in use. Here is the function I'm trying to write.</p>
  
  <pre><code>def Login():
      username=raw_input()
      password=raw_input()
      message=raw_input()
      array=[username,password,message]
  
      TCP_IP = '127.0.0.1'
      TCP_PORT = 5563
      BUFFER_SIZE = 1024  # Normally 1024, but we want fast response
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.connect((TCP_IP, TCP_PORT))
      array_string=pickle.dumps(array)
      sock.send(array_string)
      sock.close()
  
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.bind((TCP_IP, TCP_PORT))
      sock.listen(1)
  
      conn, info = sock.accept()
      while 1:
          data = serverSocket.recv(1024)
          if not data:break
      conn.send(data)  
      conn.close()
  </code></pre>