与其他网络连接的本地网络通信
首先,我对那些Internet连接属性的新手是我最陌生的,我会尽力解释我面临的问题,希望大家能帮助您。
因此,首先,我的网络公共IP是[175.139.xx]。在此网络上,我有一个NAS,其中包括IP [192.168.x.xxx],我已经在NAS中设置了MySQL Server,该服务器将运行PhpMyAdmin数据库。
现在到了要点,我已经开发了一个iOS应用程序,该应用程序在Expo小吃中使用React Native。该应用将更新或插入数据到数据库中。因此,要执行此操作,我在NAS [192.168.x.xxx]的Web文件夹中创建了一些PHP脚本,因此在React Antive代码中,当我尝试获取API时,我会喜欢此fetch(httpp) ://192.168.x.xxx/api/insert.php)
,当用户连接到与公共IP网络网络的本地网络时,所有这些功能都将完美地工作[175.139.xx]。但是,当用户使用其他Internet连接或使用其自己的移动数据时,数据将不会发送到数据库。我尝试了许多文章和网站的研究,但找不到可以克服这个问题的方法。 的链接。
这是我的代码
First of all I'm really new to those internet connection properties I would try my best to explain the problem that I faced, hope you guys help on it thanks.
So at first, my network public IP is [175.139.x.x]. On this network, I have a NAS with IP [192.168.x.xxx] I have set up MySQL server in the NAS which will running phpMyAdmin database.
Now it came to the main point, I have develop an IOS app with react native in expo snack. The app will update or insert data into the database. So to doing that action, I have create some php script inside the WEB folder in the NAS [192.168.x.xxx] so in the react native code when I try to fetch the API I would do like thisfetch(http://192.168.x.xxx/api/insert.php)
,all of this function will works perfectly when the user is connect to the local network which the network with the public IP [175.139.x.x]. But when the user is using other internet connection or using it own mobile data the data would not send to the database. I have tried research on many article and website but I can't found the ways that can overcome this problem. here is the link to my code https://snack.expo.dev/KUjWAk491
Any guidance would be appreciated. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是目标NAT的典型用途。希望您确实拥有特权(否则请您的网络管理员)来配置WAN路由器。基本上,您希望路由器将包裹的数据包传递到您的公共地址的某个TCP端口,例如175.139.xx:8080,而不是LAN地址的TCP端口80,192.168.x.xxx(作为url中的HTTP http://192.168.x.xxx/api/insert.php 使用默认的TCP端口80)。也就是说,路由器是否执行175.139.xx:8080至192.168.x.xxx:80的目标网络地址翻译。当然,您必须将获取更改为( http://175.139le /insert.php )。
请注意,在某些情况下,内部网络的人访问LAN服务器仍然希望使用公共地址 +端口(DNAT)将WAN路由器传播回vation LAN服务器,以便为地址一致性连接已开始。
This looks like a typical use of Destination NAT . I hope you do have the privilege (otherwise have your network admin do so) to configure the WAN router. Basically, you want the router to pass the packet oringinally destined to a certain tcp port of your public address e.g 175.139.x.x:8080 ,instead to the tcp port 80 of your LAN address 192.168.x.xxx (as the http in the url http://192.168.x.xxx/api/insert.php use the default tcp port 80 ). That's to say , have the router perform a destination network address translation from 175.139.x.x:8080 to 192.168.x.xxx:80 . Surely, you will have to change the fetch to (http://175.139.x.x:8080/api/insert.php) .
Note, in some cases, people from the internal network visit a LAN server would still prefer to use the public adress + port (DNAT) to have the WAN router propagate traffic back to the detination LAN server for the sake of address consistency regardless of where the connection is initiated.