Trying to understand the new UNet - no luck

i say new, i mean, i havent used unity since 3.5, and back then it was all about the network view.

anyways, i'm finding it very hard to get whats going on with the new system, so i hit the net in hopes of finding some proper IP based networking, and sadly, unity has next to no documentation other than localhost, which just doesn't cut it in todays world.

So i searched and searched and found this tutorial ... but alas, i cant get it working. i'm assuming its because i'm missing some teeny step 12 tutorial videos back or something silly, but i'm not really interested in his whole project from zero to hero, just the networking aspect.

I believe i am on the right track, but somethings not right. I cant connect at all. Just get Client timed out.

i have tried localhost 127.0.0.1 also , just to check, because in his tutorial he uses localhost as well , sigh

i have a simple playerPrefab build with a network identity component and a network transform component
i have this custom network manager code (modeled after the tutorial) attached to an empty gameObject,

i have the button wired to correct JoinGame(); I just don't understand why i cant connect.

here's the code i got

Code (CSharp):

usingSystem.Collections;

usingSystem.Collections.Generic;

usingUnityEngine;

usingUnityEngine.UI;

usingUnityEngine.Networking;

publicclass A3DNetworkManager : NetworkManager {

public InputField ipField;

publicvoid StartupHost()

{

NetworkManager.singleton.StartHost();

}

publicvoid SetPort()

{

NetworkManager.singleton.networkPort=25000;

}

publicvoid SetIpAddress()

{

NetworkManager.singleton.networkAddress= ipField.text;

Debug.Log(ipField.text);

}

publicvoid JoinGame()

{

SetIpAddress();

SetPort();

NetworkManager.singleton.StartClient();

}

publicvoid DisconnectHost()

{

NetworkManager.singleton.StopHost();

}

}

I'm hoping someone can point in the right path to IP Based connection, as local host is almost useless these days, yet so well documented and was easy quick to do ... but only through built in manager and only for lan. The new UNet has me baffled. Thanks.

I tried a script like this, as a quick test in the editor, and it worked. I used my external IP address with port forwarding. Without port forwarding, it didn't (of course), and only local worked.

Code (csharp):

publicclass Test12 : NetworkManager

{

publicoverridevoid OnClientConnect(NetworkConnection conn)

{

base.OnClientConnect(conn);

print("Hello, from client.");

}

publicoverridevoid OnServerConnect(NetworkConnection conn)

{

base.OnServerConnect(conn);

print("Server got client.");

}

void Update()

{

if(Input.GetKeyDown(KeyCode.S))

{

singleton.StartServer();

}

if(Input.GetKeyDown(KeyCode.C))

{

singleton.networkAddress="my actual ip was here";

singleton.networkPort=7777;

singleton.StartClient();

}

}

}

Click to expand...

So i have taken exactly what you have there, Methos, and made only a change to Print() cause... i have no way to view that. I tried Debug.Log() instead, didn't work, so i tried adding this Text ui, still no luck.

But after running it once, it spits out error failure to open socket on port (likely already in use)..... so i added Server.Reset()... seems to have fixed it, but i don't know. as theres no message being delivered anywhere it seems. At least not that i have been able to recieve and view / display.

Code (CSharp):

usingSystem.Collections;

usingSystem.Collections.Generic;

usingUnityEngine;

usingUnityEngine.UI;

usingUnityEngine.Networking;

publicclass Test12 : NetworkManager

{

public Text txt;

publicoverridevoid OnClientConnect(NetworkConnection conn)

{

base.OnClientConnect(conn);

txt.text="Hello, from client.";

}

publicoverridevoid OnServerConnect(NetworkConnection conn)

{

base.OnServerConnect(conn);

txt.text="Hello, from client.";

}

void Update()

{

if(Input.GetKeyDown(KeyCode.S))

{

//NetworkServer.Reset();

singleton.StartServer();

}

if(Input.GetKeyDown(KeyCode.C))

{

singleton.networkAddress="xxx.xxx.xxx.xx";

singleton.networkPort=7777;

singleton.StartClient();

}

}

}

the xxx's are actually my real ip added in.

I'm gonna try creating a simple player prefab now and working it into network, but im at a loss cause i cant really determine if anythings happening with out Print() Debug.Log() or txt UI updainting.

Does Network.Instantiate() stil work the same way? gawd, i'm fuzzled. lol Will update in a bit.

ServerBindtoIP is for when your server has multiple IP addresses, but you want it to service requests only on a single address. For example, you have a server with 2 network adapters, one that connects to an internal network, and one that connects to the Internet, you'd want to bind to the Internet adapter's IP if you are only expecting connections to come from the Internet and not from the internal network. By default it should respond on any IP address the server has. If you are using this, it would be the IP address assigned to your server, even if an internal NAT IP address, not the public IP address of your router.

Though there was a reported issue when not using ServerBindtoIP when the server has multiple IP addresses a couple years ago. I don't know if it has been fixed.

I'd really recommend having 2 computers on the same network, and get it working between them, before taking the further step of involving the router and port forwarding or DMZ settings. As already mentioned, all the tutorials use localhost because there is nothing different about using localhost and another IP address other than you then involve properly setting up firewall and port forwarding settings that differ between OS and router model.

Also be aware some company and University networks will actively block hosting servers, and possibly some home Internet providers. Which is yet another reason to try two computers on the same network first, so you know for sure your game code is solid, before you involve other hardware and services in the mix.

I can build the tutorial project and use the NetworkManager and NetworkManagerHUD to connect fine between to the two devices on android and pc build either direction using 192.168.0. etc. I even managed to find the source code for the HUD and tweak the values so the gui fits on the android properly and can be seen

however, the moment i try using my real external isp IP address , nothing works. this is what im trying to figure out.

i have changed the value in the network manager "Network Address" , i have tried just manually inputting it from either device as a client connecting to the other device : server... its just not working.

i wanted to test connection with a friend on other side of country, but nothing works except internally. i keep seeing everyone saying that the only difference from localhost to real IP based games is the address... so now im just totally friggin lost.

When i check netstat -a it shows server using port 7777, but its UDP.... shouldnt this be tcp? Also weird is that when i use the port detection web site, it claims any port i try is closed. In DMZ mode, and... with no router even attached. O>o

If you are getting a message that the address is in use, then either you didn't properly close it before or maybe it's waiting to close .. if you find port 7777 isn't normally open but becomes open (in netstat) when you start the server, then things should work.
For the record, I also couldn't see udp port 7777 open from can youseeme.org but it still worked
It is supposed to be udp, not tcp.

I may not have had the server open when i checked its visibility remotely, come to think of it, and/or perhaps it doesn't report udp ports open

As for the hosting side, that can always say localhost, and so long as it's forwarded (/dmz?), it should work, afaik. If you want to try forwarding instead of dmz just to be sure, I would do that.. then at least you can confirm.

To explain fully. My scene is now real basic, only a camera. Attached to camera is a network view, a simple server script, a simple RPC script, all as seen below.

And that's it. Basic, should work, no? But alas, not one connection made over 3 days. With DMZ activated, with Router COMPLETELY REMOVED... doesn't seem to matter. Doesn't connect.

I have also installed older version 4.5.1 3f, as noted by the networkView RPC, and even its not working. Im at a loss.

I don't understand. I do HAVE it built as a real application, not through the editor, my friend is trying to use my real IP to connect, it DOES show in netstat -s... but no listening, no connection, its not connecting.

for the record, everything else from android phones, all apps, nvidia shield tv, computer, internet, all working , no issues, just no connect through unity server / network.

you can see port 7777 is open there it seems, but no contact, no nothing.

Oops...

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.