main.py
import threading
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(
('127.0.0.1', 9900)
)
sock.listen(3)
users = []
def send_all(data):
for user in users:
user.send(data)
def listen_user(user):
print('listen')
while True:
data = user.recv(2048)
send_all(data)
def server():
while True:
user, address = sock.accept()
users.append(user)
print(address)
thread_listen = threading.Thread(target=listen_user, args=(user))
thread_listen.start()
if __name__ == '__main__':
server()
client.py
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(
('127.0.0.1', 9900)
)
while True:
client.send(input(':::').encode('utf-8'))
data = client.recv(1028)
print(data.decode('utf-8'))
вот ошибка
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\threading.py", line 932, in _bootstrap_inne
r
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
TypeError: listen_user() argument after * must be an iterable, not socket