У меня проблема с recv()
Всегда возвращается [][][][][][][][][][][][][][]...
В строке: chat = eval(s.recv(1024).decode("utf-8"))
eval выдает ошибку.
Как я могу решить эту проблему?
server.py
import socket
import threading
host = "localhost"
port = 12345
chat = []
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("socket created")
s.bind((host, port))
print("socket connected {} port".format(port))
s.listen(5)
print("socket listening")
except socket.error as msg:
print("Error:",msg)
clients = []
def accept():
while True:
global clients
client,addr = s.accept()
print('Gelen bağlantı:', addr)
clients.append(client)
client.send(str(chat).encode("utf-8"))
def new_message():
while True:
for c in clients:
message = c.recv(1024)
if message:
chat.append(message)
threading.Thread(target=accept).start()
threading.Thread(target=new_message).start()
while True:
for c in clients:
c.send(str(chat).encode("utf-8"))
Client.py
import socket
import time
from tkinter import *
import os
import threading
s = socket.socket()
host = "localhost"
port = 12345
try:
s.connect((host, port))
except socket.error as msg:
print("[Server not enabled.] Message:", msg)
while True:
pass
def render_screen():
print(s.recv(1024).decode("utf-8"))
while True:
time.sleep(0.1)
os.system("cls")
chat = eval(s.recv(1024).decode("utf-8"))
for i in list(chat):
print(i)
def send():
new_message = send_box.get()
s.send(str(new_message).encode("utf-8"))
threading.Thread(target=render_screen).start()
send_window = Tk()
send_box = Entry()
send_button = Button(text="Send",command=send)
send_box.pack()
send_button.pack()
Но здесь: chat = eval (s.recv (1024) .decode ("utf-8")) s.recv (1024) возвращение [] [] [] [] [] [] [] [] ....
Должен возвращаться только один список. Как я могу решить это?