从网络外部的设备连接到localhost

时间:2017-06-15 09:17:53

标签: java server client

我目前正在大学做一个项目,我们必须开发一个带有客户端 - 服务器架构的多人角色扮演游戏。我的部分是开发一个响应客户端请求的Java服务器。 我该怎么做才能让我的团队成员能够连接到我的localhost服务器?

2 个答案:

答案 0 :(得分:0)

If you want clients outside your local network to be able to see your server, you'll need to use something like ngrok. It's designed for exactly this. https://ngrok.com/

If your clients will be connecting from inside your network, they will need your machine's ip address. They can type it into their browser window. If you're running your java server on a port other than 80, then they'll need to add that to the url.

// from inside the network
example: http://192.168.1.125:80
example: http://192.168.1.125:3000
example: http://192.168.1.125:5000

// from outside the network
example: http://yourNgrokName.ngrok.com

答案 1 :(得分:0)

Usually all the computers (i.e. macOS, linux, windows) have at least a double interface (localhost) which is not reachable outside and an external interface (wifi or ethernet) that is reachable from outside.

On most computer systems, localhost resolves to the IP address 127.0.0.1, which is the most commonly used IPv4 loopback address, and to the IPv6 loopback address ::1. The name localhost is also a reserved top-level domain name, set aside to avoid confusion with the definition as a hostname.

If you want that your team members are able to reach your computer, you have to use the address of this second interface.

But in this case, there could be many problems related to your personal firewall, network topology and etc.

The word outside itself is very generic because, outside could mean:

  • computers in my home network (small size)
  • computers in my office network (small-medium size), may be spread across more buildings
  • all the computers on the internet

Different network problems arises when you want that you personal computer is reachable from outside.