+ 1

Why is this code giving me error?

I'm trying to build a tcp server and it keeps giving me this error, can you check out for me please? ######################################## import socket import threading server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) bind_ip = "0.0.0.0" bind_port = 9999 server.bind((bind_ip, bind_port)) server.listen(5) msg = "[*] Listening on: {0} {1}".format(bind_ip,bind_port) print(msg) def handle_client(client_socket): request = client_socket.recv(1024) msg1 = "[*] Received: ", request() print(msg1) client_socket.send("ACK!") client_socket.close() while True: client, addr = server.accept() msg2 = "[*] Accepted connection from: {0} {1}".format(addr[0],addr[1]) print(msg2) client_handler = threading.Thread(target=handle_client,args=(client,)) client_handler.start() ####################################################

28th Jun 2019, 3:38 AM
Mateus Dantas L
Mateus Dantas L - avatar
1 Answer
+ 1
It still gives me this error: ############################## [*] Listening on: 0.0.0.0 9999 Traceback (most recent call last): File "C:\Users\mathe\Desktop\tcpserver.py", line 22, in <module> client_socket.send("ACK!") NameError: name 'client_socket' is not defined #################################### Sorry for taking so long to reply to you, this website's UI is so disastrous it's awful to find where my threads are.
29th Jun 2019, 11:03 PM
Mateus Dantas L
Mateus Dantas L - avatar