def create_connection(sock: socket, port: int, host: str) -> socket: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # solution for: "socket.error: [Errno 98] Address already in use" sock.bind((host, port)) sock.listen(5) connection, client_address = sock.accept() # accept connection returns tuple print("Got connection from ", client_address) return connection
def start_server(server: socket, client_list: list): print("Started listening....") server.listen(5) while True: conn, addr = server.accept() print("\nNew connection from: " + str(addr)) client_list.append(conn) _is_running.append(False) print("reverse_tcp>", end='', flush=True)
def do_socket_logic(proxy_socket: socket, proxy_port_number): """ Example function for some helper logic, in case you want to be tidy and avoid stuffing the main function. Feel free to delete this function. """ proxy_socket.bind(("127.0.0.1", int(proxy_port_number))) proxy_socket.listen(10) cache = {} while True: client_socket, address = proxy_socket.accept() print(f"Started conn with {address}") start_new_thread(handle_client, (client_socket, cache, address)) proxy_socket.close() pass