D
D
Daniil Bakalin2016-10-16 06:04:55
C++ / C#
Daniil Bakalin, 2016-10-16 06:04:55

Unity3D. How to find a server on the local network?

Good day!
I'm a beginner Android developer and I'm making a small game with Unity. And now the question arose about the implementation of multiplayer within a local game.
Despite the huge amount of material on this topic, everywhere I have seen - an important question remains open. How can clients determine the server's IP address to establish a connection?
In all the lessons, they don't pay attention to this at all, they just indicate "and enter the ip of the server here" ... In the best case, the ip must be manually entered by the player. But this is extremely inconvenient.
My game will only work within the local network, with a maximum of a couple of dozen active ip-addresses.
And I came up with two ways for myself:
1. Iterate over all network addresses, looking for a response from the server. I did not find the way of the curve, and how to sort out only active addresses, and not in general all 255 by mask. Considering that you still need to give some time for an answer ... In general, the method is not suitable at all.
2. Store the server's IP address on an external site. Now I did just that, the ip is saved on my site, everything works as it should, but it looks, in my opinion, like a bad bike. In addition, the system will not be able to work at all in a closed network, which is extremely inconvenient.
In general, I have a feeling that I am missing some simple and convenient mechanism ...
I am far from programming network interactions, my area is graphics and UI, so I will be grateful for some simple, practical advice. This way will not be the most beautiful/fast/accurate solution, but if I can quickly tie it to my application (ideally by downloading the asset from the store) - I will be very grateful to you!
Now the application is implemented on the Unity Network (UNet) following the example of the chat. I don't need a "real" multiplayer, it's enough to exchange text commands between each of the clients and the server.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2016-10-16
@Quiensabe

UDP broadcast: 255.255.255.255
Then those clients who want to be seen in response packets will respond - their IPs will be.

R
Rou1997, 2016-10-16
@Rou1997

You are mistaken, you are not missing anything, there is no such mechanism, therefore, in global networks, the server must also have a static (permanent) IP, otherwise it is inconvenient to connect to it and domain parking is impossible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question