Hey guys, I need to know if is possible to make a multiplayer mobile game without internet connection, using only the same wireless (LAN) with UNet. I'm trying to do it since the UNet was lauched. The connection works perfectly at the same machine (computer-computer), but not in different machines (computer-mobile, computer1-computer2, mobile-mobile). I don't have too much experience in network area, maybe you will see some illogical code of my part. This is my NetManager: Code (CSharp): using UnityEngine; using System.Collections; using UnityEngine.Networking; public class NetManager : NetworkManager { public UnityEngine.UI.Text hostAddress, joinAddress; public void CreateLocalGame() { NetManager.singleton.StartHost(); GameController.Instance.isServer = true; networkAddress = hostAddress.text; } public override void OnStartHost () { GameController.Instance.mainPanel.MovePanel(1); } public override void OnStopHost () { if(!GameController.Instance.isServer) { GameController.Instance.mainPanel.disconectedText.text = "The host was disconnected"; GameController.Instance.mainPanel.DisconnectDialogPanel(); } } public override void OnClientDisconnect (NetworkConnection conn) { if(GameController.Instance.isServer) { GameController.Instance.mainPanel.disconectedText.text = "The player was disconnected"; GameController.Instance.mainPanel.DisconnectDialogPanel(); } } public void JoinLocalGame() { GameController.Instance.isServer = false; NetworkManager.singleton.StartClient(); networkAddress = joinAddress.text; } /*public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId) { Vector3 spawPos = Vector3.right * conn.connectionId; GameObject player = Instantiate(base.playerPrefab, spawPos, Quaternion.identity) as GameObject; NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); }*/ } There something that I miss? It's hard to a mobile hold a nethost? I will need to work with LLAPI? Sorry for my bad english
I've been testing over my LAN between different pc's and tablets fine, using the local network IP address of the server to connect(eg 192.xxx.xxx.xxx). I did need to forward ports for the server when attempting to connect over the net though. I've not yet tried hosting from an android device. My host/connection code is very simple at the moment, to start a server I set the port and then StartHost() ie: netManager.networkPort = serverPort; netManager.StartHost(); And then to connect from a client: netManager.networkPort = serverPort; netManager.networkAddress = serverIP; netManager.StartClient(); Perhaps you're missing setting ports?
Are you using NetworkClient to get the serverPort and Ip? How do you get the server ip and port? If you are using NetworkClient, accord to the documentation "The port/ip of the server that this client is connected to." It's not make sense to me... maybe because I'm newbie with network.
The server IP is just the IPaddress the machine is using on the local network (you can find that either with ipconfig from a cmd prompt on a windows machine, or perhaps from your router/switch), and the port is explicitly set when starting the server. The way I'm set up currently is just a direct connect type of thing, so I have the client input that IP & port via some UI elements, which the connection script can grab and use.
I've made some changes in my code Code (CSharp): public class NetManager : NetworkManager { public UnityEngine.UI.Text joinPort, joinAddress; int port = 1978; public void CreateLocalGame() { NetworkManager.singleton.networkPort = port; NetworkManager.singleton.StartHost(); GameController.Instance.isServer = true; AddressData() } public override void OnStartHost () { GameController.Instance.mainPanel.MovePanel(1); } public override void OnStopHost () { if(!GameController.Instance.isServer) { GameController.Instance.mainPanel.disconectedText.text = "The host was disconnected"; GameController.Instance.mainPanel.DisconnectDialogPanel(); } } public override void OnClientDisconnect (NetworkConnection conn) { if(GameController.Instance.isServer) { GameController.Instance.mainPanel.disconectedText.text = "The player was disconnected"; GameController.Instance.mainPanel.DisconnectDialogPanel(); } } public override void OnClientConnect (NetworkConnection conn) { if(conn.connectionId != -1) { CancelInvoke("SendData"); Debug.Log("Stoped send data"); } } public void JoinLocalGame() { GameController.Instance.isServer = false; NetworkManager.singleton.networkAddress = joinAddress.text; NetworkManager.singleton.networkPort = int.Parse(joinPort.text); NetworkManager.singleton.StartClient(); //StartReciver(); } void AddressData() { Debug.Log("Network ip: " + Network.natFacilitatorIP); Debug.Log("Network port: " + Network.natFacilitatorPort); Debug.Log("Networkplayer ip: " + Network.player.ipAddress); Debug.Log("Networkplayer port: " + Network.player.port); Debug.Log("Networkplayer external ip: " + Network.player.externalIP); Debug.Log("Networkplayer external port: " + Network.player.externalPort); Debug.Log("NetworkManager ip: " + NetworkManager.singleton.networkAddress); Debug.Log("NetworkManager port: " + NetworkManager.singleton.networkPort); Debug.Log("//////////////"); } } That is the return of the logs: I've made all combinations with ip and port to connect my android with the computer... but no return... I'm getting crazy! What is the localhost ip?? T.T
May i know how you solved your problem. i am also trying to connect 1 machine build (pc or mac) running as server and one device build (ios/android) running as client over the network. i have tried to connect 1 to 1 using localhost and everything seams ok, by entering server ip i.e Host machine (pc or mac). But the issue, if i start two host (one is on mac and one is on window), then how could i show those two machine on clients build (on android or ios device). What is the way to show list of available servers? could you please help me?
That you want to do is send message over the local network, take a look in this answear: http://answers.unity3d.com/questions/571052/networking-masterserver.html . You will need to create a lobby system that will manage the multiple messages sent by servers.
Hey there @iagoccampos I'm really struggling and I could really use some help. I'm trying to build an co-operative puzzle app such that the users will create a lan and play it whithin. I can't see though how I can make the server see the client and vice versa. Should I use the LobbyManager component ? Should I use some script with NetworkManager ? Thanks in advance !