two*_*e88 4 python sockets bind
在作为客户端连接之前,我需要将我的套接字绑定到特定的本地IP.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.1.2", 33333))
s.connect(("google.com", 80))
s.send("test")
Run Code Online (Sandbox Code Playgroud)
我知道如何绑定到特定的本地IP地址,但我不知道指定哪个端口.我不能使用随机端口,因为它可能已经在使用中.有没有办法绑定到任何可用的端口?