Answer the question
In order to leave comments, you need to log in
Why is an error being thrown?
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()
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'))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question