title: Python - A request to send or receive data was disallowed because the socket is not connected
body: <p>I am creating a game in Pygame that requires a client-server part for the multiplayer.</p>
  
  <p>First, I am checking if there are less than two connections. If this is the case, the client will be shown a screen that says 'waiting for connections'. </p>
  
  <p>I have got the client to successfully send a '1' message to the server, which will respond with a '1' if the server is not full. Therefore, if the server does not respond with a 1, the server is full, and the client can continue.</p>
  
  <p>However, I am getting this error mentioned in the title.</p>
  
  <p>Server code:</p>
  
  <pre><code>import socket
  import sys
  import threading
  from _thread import *
  import time
  
  s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  host=socket.gethostname()
  ip=socket.gethostbyname(host)
  port=8000
  
  connections=[]
  
  print('Your local ip address is',ip)
  
  s.bind((host,port))
  s.listen(2)
  
  def  threaded_client(connection):
  
      while True:
          data=connection.recv(2048) #anything we receive
          if not data:
              break
  
      connection.close()
  
  
  def checkconnected(connections):
      noofconn=len(connections)
  
  
  
  while True:
  
      print('Waiting for a connection...')
      connection,address=s.accept()
      print(address,'has connected to server hosted at port',address[1])
      connections.append(address)
  
  
  
      data=connection.recv(1024)
  
      received=[]
      counter=0
  
      for letter in data:
          received.append(data[counter])
          counter+=1
  
      received=(chr(received[0]))     
  
      if received=='1':#handling initial connections
          if len(connections)!=2:
              s.sendall(b'1')
  
      if not data:
          break
  
  
      start_new_thread(threaded_client,(connection,))
  
  
  s.close()
  </code></pre>
  
  <p>The client code that calls it:</p>
  
  <pre><code>host=socket.gethostname()
              ip=socket.gethostbyname(host)
              s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
              address=address
              port=8000
  
              if address==ip:
                  ishost=True
  
              else:
                  ishost=False
  
              try:
                  s.connect((address,port))
                  connectionwaitingmenu()
                  connected=False
  
                  while connected==False:
                      s.sendall(b'1')
                      data=s.recv(1024)
                      received=[]
                      counter=0
  
                      for letter in data:
                          received.append(data[counter])
                          counter+=1
  
                      received=(chr(received[0])) 
  
                      if received=='1':
                          connected=False
                      elif received!='1':
                          connected=True
                          classselection()
  </code></pre>
  
  <p>The error occurs on the s.sendall(b'1') line in the server code.</p>