这是我的代码:user_input = input("What port would you like to use? ")def output(name): print(f'Set Port {name}')output(user_input)Hello123 = input(f'Please Choose A IP Address ')if Hello123 == '127.0.0.1': print('WARNING PLEASE BE SURE YOU KNOW WHAT YOUR DOING BEFORE YOU SET THIS')def output(ipaddr): print(f'Set Ip {ipaddr}')output(Hello123)HOST = (f'{ipaddr}')PORT = (f'{name}')server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind((HOST, PORT))`我正在 python 中创建一个套接字,我希望它是 {HOST} 的 ipaddr 和用户输入我也想对 PORT 和 {name} 执行相同的操作
1 回答
慕森王
TA贡献1777条经验 获得超3个赞
以下应该有效:
port = int(input("What port would you like to use? ")) host = input("What host would you like to use? ") server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind((host, port))
添加回答
举报
0/150
提交
取消