Unity NetworkManager component, IP for LAN?

匿名 (未验证) 提交于 2019-12-03 01:35:01

问题:

In Unity's new networking, I have two computers side by side on the same WiFi network.

Using NetworkManager, I am trying to network them over the LAN.

TBC, absolutely nothing to do with global internet networking, and not on localhost.

On the left is 192.168.0.26.

On the right is on 192.168.0.120.

Say we want the left one to be the server, i.e. simply using

    Debug.Log("I'm now a server");     networkManager.StartServer(); 

Say we want the right one to be a client (So, StartClient() .)

TBC I simply looked at ipConfig/etc on the two computers, to get the current local IP.

I absolutely ensured both machines have the firewall open for Unity editor (an infuriating gotchya).

In fact, which "NetworkAddress" (see image) do you use? On the two machines?

There are four permutations.

I just cannot get them to connect over LAN - what should the network address be?


Footnote: For anyone googling here be aware of this critical tip about Unet ... https://stackoverflow.com/a/51759299/294884

回答1:

Wen using the default Network Manager provided by Unity, you have to make sure the Network Address field contains the local IP (provided by your router) of the machine you want to use as a server. In your case this IP is equal to 192.168.0.26 and can be found in the network configuration of the machine.
Every instance of client/server must use this IP address from now on in order to know where to connect to.

Something I personally recommend when creating the server is using the networkManager.StartHost(); instead of the networkManager.StartServer(); since your server perhaps also needs a client. If that's not the case please ignore this statement.

And lastly if you are up to the task, you can consider making your own Custom Networking Manager that inherits from the Network Manager. That way you could be in control of your app's networking even more.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!