gpt4 book ai didi

objective-c - UPnP 端口映射,服务不接受连接

转载 作者:行者123 更新时间:2023-12-03 17:11:43 26 4
gpt4 key购买 nike

我设置了一个简单的套接字,它将接受端口 1337 上的连接。它接受通过本地主机的连接:

$ nc -vv localhost 1337
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 57224
dst ::1 port 1337
rank info not available
TCP aux info available

Connection to localhost port 1337 [tcp/menandmice-dns] succeeded!
^C

我使用 Cocoa-PortMapper ( https://github.com/mugginsoft/Cocoa-PortMapper ) 将此端口转发到我后面的 NAT 路由器。

portMapper = [[PortMapper alloc] initWithPort:1337];

portMapper.desiredPublicPort = 1337;

[[NSNotificationCenter defaultCenter] addObserverForName:PortMapperChangedNotification object:portMapper queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"Successfully mapped: %@", portMapper.isMapped ? @"YES" : @"NO");
NSLog(@"Mapped %@:%hu", portMapper.publicAddress, portMapper.publicPort);
}];

if(![portMapper waitTillOpened]) {
NSLog(@"Could not open port");
}

它返回 YES,在我的路由器 UPnP 端口映射表中,我可以看到外部端口 1337 上有一个事件的 TCP 映射到我的计算机本地 IP 上的内部端口 1337。

但是,通过外部IP连接到服务不起作用:

$ nc -vv xxx.89.136.xx 1337
nc: connectx to xxx.89.136.xx port 1337 (tcp) failed: Connection refused

如果我在路由器中手动设置端口转发规则,则连接可以正常工作。为什么 UPnP 端口映射不起作用,尽管我的路由器说它可以工作?

最佳答案

事实证明,端口映射是在我的网络外部工作的。当我从其他地方连接服务器时,但当我通过外部 IP 从本地计算机连接时则不然。

关于objective-c - UPnP 端口映射,服务不接受连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22656627/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com