evavaalundroth
Newbie
- Oct 25, 2021
- 4
- 0
Ok so, I'm reading through Black Hat Python 2nd Edition, and it's excellent. I'm working on the TCP Server right now, but there's a problem in the code on the client_handler = line. It seems to have some sort of indentation or syntax issue, I'm not really sure which. It gives me the error Expected ")" Pylance [17,9]. I'm not really sure what it wants. Anyways, here's the code.
import socket
import threading
IP = '0.0.0.0'
PORT = 9998
def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((IP, PORT)) (1)
server.listen(5) (2)
print(f'[*] Listening on {IP}:{PORT}')
while True:
client, address = server.accept() (3)
print(f'[*] Accepted connection from {address[0]}:'
'{address[1]})'
client_handler = threading.Thread (target = handle_client, args = (client,))
client_handler.start() (4)
def handle_client(client_socket): (5)
with client_socket as sock:
request = sock.recv(1024)
print(f'[*] Received: {request.decode("utf-8")}')
sock.send(b'ACK')
if __name__ == '__main__':
main()