K
K
kingslayer2021-08-06 14:33:06
Python
kingslayer, 2021-08-06 14:33:06

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()

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'))

here is the error
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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirillinyakin, 2021-08-06
@kingslayer

args = (user, )
When the thread is started

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question