简体   繁体   English

将Android设备连接到在我的PC上运行的Tomcat服务器

[英]Connect android device to Tomcat server running on my PC

I am trying to connect with my device to the local Tomcat server by IP not with localhost. 我正在尝试通过IP(而不是localhost.将设备连接到本地Tomcat服务器localhost. If I can work this out probably I will do it in Android too. 如果我可以解决这个问题,也许我也会在Android中完成。

I know that I have to connect the device and PC to the same Wi-Fi. 我知道我必须将设备和PC连接到同一Wi-Fi。

I have a question: It's a problem if I connect to the internet with a proxy? 我有一个问题:如果我使用代理连接到互联网,这是一个问题吗?

For example http://localhost:8080/create it's working on my PC when I deploy my app. 例如,当我部署应用程序时, http:// localhost:8080 / create可以在我的PC上运行。

I tried to set Windows Firewall off or to create a new Rule(Inbound Rules) for port 8080 but it didn't work for me. 我试图关闭Windows防火墙或为port 8080创建新规则(入站规则),但是它对我不起作用。 When I tried to connect to the server from my PC using the IP(I got it from cmd -> ipconfig IPv4 ) it did't work(192.168.0.101:8080/create). 当我尝试使用IP从PC连接到服务器(我是从cmd -> ipconfig IPv4 )时,它不起作用(192.168.0.101:8080/create)。

I read many post on stack about this even tried to add a new environment variable for JAVA ( JAVA_OPTS="-Djava.net.preferIPv4Stack=true" ). 我在堆栈上阅读了很多关于此的文章,甚至试图为JAVA添加新的环境变量( JAVA_OPTS="-Djava.net.preferIPv4Stack=true" )。 I did this in cmd with the command: setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true and received SUCCESS: Specified value was saved. cmd with the command: setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=truecmd with the command: setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true并收到成功:已保存指定的值。 Even changed the server.xml in \\Tomcat 9.0\\conf. 甚至更改了\\ Tomcat 9.0 \\ conf中的server.xml。 Here is my Connector: 这是我的连接器:

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
               address="0.0.0.0"/>

I can access the server in the emulator with this IP: 10.0.0.2:8080/create. 我可以使用以下IP访问仿真器中的服务器:10.0.0.2:8080/create。 How I do it now for devices?? 我现在如何为设备做呢? What I am missing. 我所缺少的。 Can you guide me step by step how to do it? 你能指导我一步一步去做吗?

How to fix the problem: 如何解决问题:

My tomcat is embedded so I created a file in /resources named application.properties and added: server.address=<http://192.168.0.101> and turned off Firewall. 我的tomcat是嵌入式的,因此我在/ resources中创建了一个名为application.properties的文件并添加: server.address=<http://192.168.0.101>并关闭了防火墙。

Good luck! 祝好运!

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

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