如何使用通过不同wifi连接到Internet的IP地址连接客户端和服务器? [英] How to connect client and server with the help of ip address which are connected to internet through different wifi?

查看:113
本文介绍了如何使用通过不同wifi连接到Internet的IP地址连接客户端和服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将笔记本电脑用作服务器,将移动设备用作客户端.我需要在它们之间发送消息.我可以通过使用笔记本电脑的本地IP地址并将它们都连接到同一个wifi网络来做到这一点.但是,如果我需要发送消息,尽管它们通过不同的wifi网络连接到不同的互联网,但我该如何使用ip地址. 这是客户端中的代码:

I am using a laptop as my server and a mobile device as my client. I need to send messages between them. I am able to do that by using the local ip address of the laptop and connecting them both to the same wifi network. But how I do use the ip address if I need to send messages though they are connected to different internet through different wifi networks. This is the code in client:

 client = new Socket("192.168.0.103", 4444); //local ip address of server

这是服务器中的代码:

serverSocket = new ServerSocket(4444);  //Server socket
clientSocket = serverSocket.accept();   //accept the client connection
inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); //get the client message
String input=bufferedReader.readLine();

我可以使用网关还是动态或静态IP来解决此问题?如果可以,怎么办?

Can I use gateways or dynamic or static ip to solve this problem ? If so how?

推荐答案

您需要在服务器端配置调制解调器/路由器,以便将外部呼叫(从客户端mobil转移到端口4444)重定向到正确的设备在子网中.

You need to configure the modem/router on the server side so that external calls (from the client mobil) to the port 4444 will be redirected to the correct device in the subnet.

这是配置更改,必须在路由器上手动完成.另外,并非所有路由器都支持此服务重定向功能(但大多数路由器都支持).即使路由器支持它,有时也可能很难找到正确的方法,因为这在模型之间可能具有不同的名称.

This is a configuration change that must be done manually on the router. Also, not all routers support this function of service redirecting (but most of them do). Even when a router supports it, sometime it might be hard to find the correct way of doing it because this can have different names between models.

通常,即使路由器上连接了单个设备,也必须执行此操作.

Usually, you must do this even if there is a single device connected to the router.

在某些安装中,路由器和型号是两个不同的物理设备,但您也可以在一个设备中找到这两个功能.如果您具有将多个设备连接到调制解调器的功能,那么调制解调器还可以提供路由功能.但是,我记得过去曾经看到过某些调制解调器,无法将外部服务调用重定向到特定设备(或者至少,我个人从来没有找到如何在这些型号上执行此操作).

On some installations, the router and the model are two different physical devices but you can also find these two functions united inside a single device. If you have the capabilities of connecting multiple devices to your modem then likely, your modem also offer the routing functionality. However, I remember seeing in the past some modems for which it was impossible to redirect external service calls to a particular device (or at least, I personally never find how to do this for these models).

如果您的网络只有一个路由器-就像大多数家庭安装一样;那么网关和路由器之间就没有真正的区别.但是,如果您的服务器位于具有多个路由器的复杂本地网络上,则很难正确配置整个网络.尤其是当您进行安全检查时.

If your network has a single router - like in most home installations; then there is no real difference between a gateway and a router. However, if your server is located on a complex local network with multiple routers, then it can become very hard to properly configure the whole network; especially when you have security checks put into place.

因此,如果您在家,则应查阅wify设备的文档,或请负责公司网络的人员进行配置.

So, you should either consult the documentation for your wify device if you are at home or ask the person responsible for the company network to do the configuration.

这篇关于如何使用通过不同wifi连接到Internet的IP地址连接客户端和服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆