title: Variable (suddenly) becomes None after referencing outside while loop. Sockets in Python 3
body: <p>I am trying to make two simple functions that use sockets and act as a server/client for sending some text. </p>
  
  <p>I can send text and print it out but when I store it in a variable and try to access it <strong>outside</strong> the <code>while</code> loop <strong>which it was created in</strong>, the variable becomes <code>None</code>.</p>
  
  <p>Here is my (full, because it's really small) code:</p>
  
  <p>send.py (the client):</p>
  
  <pre><code>import socket   
  def send(HOST2 = "localhost", PORT2 = 50007,):
      s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s2.connect((HOST2, PORT2))
      s2.sendall(b"Hello, world!")
      s2.close()
  send()
  </code></pre>
  
  <p>The code above works as expected.</p>
  
  <p>recive.py (the server):</p>
  
  <pre><code>import socket
  def recive(HOST = "localhost", PORT = 50007):
  
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.bind((HOST, PORT))
      s.listen(1)
      conn, addr = s.accept()
      while True:
          global data
          data = conn.recv(1024).decode("ascii") 
          print(data) #This will print correctly as expected
          if not data: break
      conn.close()
  recive()
  print(data) #This is None
  </code></pre>
  
  <p>My question is how to use the variable data outside the loop. For some reason it is None. My guess is that it has to do something with local/global variables or it is the way socket module behaves.</p>
  
  <p><strong>EDIT:</strong> I have changed the code and the problem is still there.
  Changes: Added <code>recive()</code> and <code>send()</code> calls.</p>