简体   繁体   English

从网络中的另一台计算机访问本地主机(在Mac OS X上运行)

[英]Access localhost ( running on Mac OS X ) from another machine in the network

I have a REST service running on Mac OS X, which im currently accessing using " localhost:8888 " and " 10.0.2.2:8888 " 我有一个在Mac OS X上运行的REST服务,当前正在使用“ localhost:8888 ”和“ 10.0.2.2:8888 ”进行访问

I want to access the same service from another computer which is in the same network. 我想从同一网络中的另一台计算机访问相同的服务。

I disabled the firewall also and I typed 我也禁用了防火墙并输入了

 nc -v 192.168.1.3 8888

and got the result as 并得到了结果

nc: connectx to 192.168.1.3 port 8888 (tcp) failed: Connection refused

currently i use localhost (to access using java application) and 10.0.2.2 (to access using android application runs in the simulator) which both runs on the same machine which the server runs too. 目前,我使用本地主机(使用Java应用程序访问)和10.0.2.2(使用在模拟器中运行的android应用程序访问),它们都在服务器也运行在同一台计算机上运行。

I want to put the android application to my phone and give the machine ip addess ( because if i connect to internet via wifi, it'll be in the same local area network) i should be able to access my service runs on my machine. 我想将android应用程序放到我的手机上,并给机器添加IP地址(因为如果我通过wifi连接到互联网,它将在同一局域网中),我应该能够访问在我的机器上运行的服务。

can some one please tell me what im doing wrong here? 有人可以告诉我我在这里做错什么吗? Thank you 谢谢

You can't access localhost from your front end code. 您无法从前端代码访问localhost。 It needs to refer to the server's name or address. 它需要引用服务器的名称或地址。

The localhost address should be 127.0.0.1 , which is in the loopback range of addresses. 本地主机地址应为127.0.0.1 ,这在地址的回送范围内。 Any address in the 127.0.0.0/8 block can never appear anywhere on any network, nor can any address in that block be used as a source or destination address outside a host. 127.0.0.0/8块中的任何地址都永远不会出现在任何网络上的任何地方,该块中的任何地址都不能用作主机外部的源地址或目标地址。 It is not possible for one host to access anything in that address range on another host. 一台主机不可能访问另一台主机上该地址范围内的任何内容。

The goes back at least as far as RFC 990, ASSIGNED NUMBERS : 至少可以追溯到RFC 990,ASSIGNED NUMBERS

The class A network number 127 is assigned the "loopback" function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. A类网络号127被分配了“回送”功能,也就是说,由更高级别的协议发送到网络127地址的数据报应在主机内部回送。 No datagram "sent" to a network 127 address should ever appear on any network anywhere. “发送”到网络127地址的任何数据报都不应出现在任何地方的任何网络上。

RFC 1122, Requirements for Internet Hosts -- Communication Layers : RFC 1122,Internet主机的要求-通信层

(g) { 127, } (g){127,}

Internal host loopback address. 内部主机环回地址。 Addresses of this form MUST NOT appear outside a host. 这种形式的地址一定不能出现在主机外部。

Also RFC 3330, Special-Use IPv4 Addresses : 也是RFC 3330,特殊用途的IPv4地址

127.0.0.0/8 - This block is assigned for use as the Internet host loopback address. 127.0.0.0/8-此块分配为用作Internet主机回送地址。 A datagram sent by a higher level protocol to an address anywhere within this block should loop back inside the host. 由更高层协议发送到该块内任意位置的地址的数据报应在主机内部循环。 This is ordinarily implemented using only 127.0.0.1/32 for loopback, but no addresses within this block should ever appear on any network anywhere [RFC1700, page 5]. 通常,仅使用127.0.0.1/32进行环回即可实现此功能,但是此块中的地址都不得出现在任何网络上的任何地方[RFC1700,第5页]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM