我正在尝试允许我的代码从其他网络上的设备运行。这里的代码是我的服务器。我的问题是,如果我希望有人能够访问网络,我的路由器上的端口转发设置是否可以将我的外部IP或内部IP置于端口转发设置中?当我执行客户端尝试连接时,我是否给他们外部IP和端口或内部IP和端口尝试连接?
import sockets
def main():
port = None
host = str(input("Enter ip to host on:"))
if host == "port_forward"
host = "192.xxx.x.x"
port = 9856
elif host == "my_ip":
host = socket.gethostbyname(socket.gethostbyname())
port = int(input("Enter port to listen to"))
else:
port=int(input("Enter port to listen to"))
s = socket.socket()
s.bind((host,port))
print("Host: "+host + " port:"+str(port))
s.listen(1)
c, addr = s.accept()
print("Connection from:" +str(addr))
while True:
data = c.recv(1024).decode('utf-8')
if not data:
break
print("from connected user:")
data = input("Enter text to send.")
c.send(data.encode('utf-8'))
c.close()
main()