How to organize the interaction between java server and android client in your local network?

The bottom line is this: is installed on the computer application that acts as a server for the local network. The client application on the Android device must connect to the same local network and pokidajut to the server some data. Everything seemed to be fine - the server works fine, but Android doesn't want to connect according to the diagram new Socket("localhost", port); For the test wrote the client on your PC - everything works in this ad. I understand that I need to do something on the part of Android and to understand this, first thought - perhaps we should specify more explicitly the IP, but I'm not sure that's the problem, of course. If you suggest a solution to the problem and how to communicate in the local network - I would be very grateful.
PS it is understood that "server" on a PC application that can supply any person and interact with it from your phone.
PS.s when you explicitly specify the ip address of konekt's going on, but the question again is that every new computer it your. My idea - display PC IP, which must be entered in the mobile client for konekta. Don't really like this solution, I would like to hear more educated decisions
March 19th 20 at 08:44
1 answer
March 19th 20 at 08:46
Of course, to localhost, the Android will not connect! Since localhost to the address, which is responsible for local (loopback) interface on your device. This address is on every device or computer that is created to network programs within the operating system.
In other words, You need to set the connection ip address of the computer on which spouse server.
Well, exchange is fine, the http/https Protocol, and to connect easier and your Protocol should not be written, many frameworks and libraries are there for this. On the client side is fine httpok, server - springboot, jooby, spartjava and a couple dozen others, including tomcat and jetty.
springboot is nice and all would be well and quickly done, but then ideologically not suitable, don't even ask why. :) Yeah, maybe, with the theme of localhost works only for the client PC, I already realized by the method of practical italiane ip. In this regard, beautiful solution to the determine the IP of the server is important, I'll try to find it - Geovany77 commented on March 19th 20 at 08:49
@Geovany77, no, no, no. It asks, what is the ideology? Why do I and virtually all of this works for hundreds-thousands of devices, and You can't?
I know dozens of protocols, some implemented personally, but in nearly 30 years of practice prefer http, and in very rare cases I will look for something special. - Braede commented on March 19th 20 at 08:52
@Braede, rear is. It would be better helped with the decision that I will not be able to everyone who will download the server application to come home and manually enter their IP.
And the fact that a commercial scale to use the streamlined things - such themselves, I fully understand - Geovany77 commented on March 19th 20 at 08:55
Well, porobuyte on Android to open server udp socket and listen to the stream address. From the server once per second for example send stream message with your ip server - Braede commented on March 19th 20 at 08:58
@Braede, I'm with Android is not very good, so many do not know the details. The essence of the thing: now, on the emulator everything works fine, so, everything is beautiful as I wanted. And phone sockets stupidly did not connect. it roughly when you click "start" soumskaya something like connection = new connection(ip, port), and inside this conexan all work with soekamo already happening. But on the phone nothing happens, does not connect. Maybe what permissions need to give or prescribe something? - Geovany77 commented on March 19th 20 at 09:01
@Geovany77, it's probably just permissions. But in my Android did almost nothing.. - Braede commented on March 19th 20 at 09:04

Find more questions by tags AndroidJava