когда я закрываю 4 клиента, все работают, но когда я закрываю 5 клиентов, все отключаются от сервера, но когда я снова открываю игру, сервер получает сообщение, но не отправляет, этот код вызывается, когда я закрываю клиента
def close_client(index):
index = int(index)
while int(index) >= len(all_clients) and all_clients.__len__() > 0:
print("index go down")
index -= 1
all_client_index = 0
for c in all_clients:
if all_client_index == int(index):
name = c['name']
if name != "":
close_player(name)
all_client_index += 1
while int(index) >= len(all_clients) and all_clients.__len__() > 0:
print("index go down")
index -= 1
all_clients.pop(index)
print("online player : {0}".format(all_clients.__len__()))
new_index = 0
for i in all_clients:
try:
i['client'].sendall("you index is/{0}*".format(new_index).encode())
except:
continue
new_index += 1
# send to all client that the player close
if name != "":
for i in all_clients:
if i['name'] != "":
try:
name = RemoveSpace(name)
LeaveChat(name, i['client'])
# i['client'].sendall("{0} leave the
chat/{0}/{1}*".format(name, 5).encode())
except:
continue
Это код, который подключается к базе данных
def connect_db():
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="game_db",
buffered=True,
autocommit=True
)