Answer the question
In order to leave comments, you need to log in
How to organize interactions between a java server and an android client on a local network?
The bottom line is this: an application is installed on the computer that acts as a server for the local network. The client application on the android device must connect to the same local network and transfer some data to the server. Everything seemed to be fine - the server works fine, but the android does not want to connect using the new Socket("localhost", port); For the test, the client wrote on the PC - everything works with such an announcement. I understand intellectually that I need to do something from the side of the android and understand this, the first thought is that it might be worth specifying a more explicit IP, but I'm not sure that this is the problem, of course. If you can generally suggest a solution to the problem and how to organize interaction in the local network, I will be very grateful.
Zs it is understood that the "server" on the PC is an application that anyone can install and interact with it from their phone.
Zy when explicitly specifying the ip address, the connection occurs, but the question is again that it has its own on each new computer. My idea is to display the IP on the PC, which will need to be entered in the mobile client for the connection. I do not really like this solution, I would like to hear more competent solutions
Answer the question
In order to leave comments, you need to log in
Of course, the android will not connect to localhost! Since localhost corresponds to the address 127.0.0.1, which is responsible for the local (loopback) interface of its own device. This address is on every device or computer and was created for the interaction of network programs within the operating system.
In other words, you need to specify the ip-address of the computer on which the server is running to connect.
Well, the http / https protocol is quite suitable for the exchange, and it’s easier to connect and you don’t need to write your own protocol, and there are a lot of framework libraries for this. On the client side, httpok is fine, on the server side - springboot, jooby, spartjava and a couple of dozen others, including tomcat and jetty.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question