简体   繁体   English

无法通过 WAN 将客户端程序连接到服务器程序

[英]Unable to connect client program to server program over WAN

I have created a client server program on java language with serversocket and socket classes with datainputstream and dataoutputstream for sending and receiving data.我在 java 语言上创建了一个客户端服务器程序,该程序带有用于发送和接收数据的 serversocket 和带有 datainputstream 和 dataoutputstream 的套接字类。

But the problem is that when I run it on LAN(local area network) or localhost it works properly but when I try to connect client with server over WAN (wide area network) it doesn't even connects to server但问题是,当我在 LAN(局域网)或 localhost 上运行它时,它可以正常工作,但是当我尝试通过 WAN(广域网)将客户端与服务器连接时,它甚至没有连接到服务器

And to connect it over WAN I have entered ip address of server side program as parameter of socket class's contractor ex: socket s= new socket(ipadd,port);为了通过 WAN 连接它,我输入了服务器端程序的 ip 地址作为套接字类承包商 ex 的参数:socket s= new socket(ipadd,port); and it doesn't connects to server without any error or something并且它没有任何错误或其他东西无法连接到服务器

So please help me out I am stuck on this problem from a long time.所以请帮助我,我很长时间以来都被困在这个问题上。

This is my server side program code这是我的服务器端程序代码这是我的服务器端程序

This is my client side program code这是我的客户端程序代码这是我的客户端程序代码

You are using your mobile phone to provide internet to your server(which is your laptop in your case), so here your mobile is acting as a router, and your mobile has provided local ip addresses to devices that connects to it.您正在使用您的手机为您的服务器(在您的情况下是您的笔记本电脑)提供互联网,因此您的手机在这里充当路由器,并且您的手机已向连接到它的设备提供本地 ip 地址。 So what is happening is that when you enter your laptop's (server) ip address in client application for starting connection and your computer doesn't have any ip address in public(it has an ip address which is assigned by your mobile but it's not publically available and it's a local ip address which generally starts with 192.168........) so client app is unable to detect your server and servers which are connected to routers same is applied in their case.所以发生的事情是,当您在客户端应用程序中输入笔记本电脑的(服务器)ip 地址以启动连接时,您的计算机没有任何 ip 地址公开(它有一个 Z957B527BCFBAD2E80F358D2068393 的公共地址,但它不是由您的手机分配的,但不是 Z957B527BCFBAD2E80F358D2068391可用,它是一个本地 ip 地址,通常以 192.168........ 开头),因此客户端应用程序无法检测到您的服务器和连接到路由器的服务器,同样适用于他们的情况。

So solution to this is, you enter your mobile's (which is providing internet to your server) ip address in your client application, and with any port forwarder application you do port forwarding to your server's(which is your laptop) ip address(and it's local ip address assigned by your phone/router to your laptop) and port(which you are using for communication with client), and there are many port forwader applications available on Google play store you can use anyone of them.所以解决方案是,您在客户端应用程序中输入您的手机(为您的服务器提供互联网)ip 地址,并使用任何端口转发器应用程序将端口转发到您的服务器(即您的笔记本电脑)ip 地址(它是本地 ip 地址由您的手机/路由器分配给您的笔记本电脑)和端口(您用于与客户端通信),Google Play 商店中有许多端口转发器应用程序,您可以使用其中任何一个。 So steps to start connection with client and server in your case are:因此,在您的情况下,开始与客户端和服务器建立连接的步骤是:

1: install and start any port forwader application in your phone from your mobiles store. 1:从手机商店安装并启动手机中的任何端口转发器应用程序。 2: unable port forwarding (for every request which comes to your mobile's ip address) to your server's ip address (which is assigned by your mobile to your server). 2:无法将端口转发(对于到达您手机的 ip 地址的每个请求)到您的服务器的 ip 地址(由您的手机分配给您的服务器)。 3: Than enter your mobile's ip address in your client application. 3:比在您的客户端应用程序中输入您手机的 ip 地址。

And it will get connected to your server...它将连接到您的服务器...

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

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