- Home /
Simple Easy Networking using Wireless Internet
I am a student at tech high school and for a project we are trying to build a networked game in unity. we started out trying to make an mmo but then decided we could settle for something a little less ambitious. Before you say i didn't look hard enough, i have been looking for 2 weeks and havent found anything simple that works and explains in detail what exactly i have to do. Basically i just need a clear way to network between 2 computers so that 1 is the server and the other is the client using the wireless internet. the more detailed the better since i am a beginner programmer.
Answer by asafsitner · Feb 09, 2012 at 07:18 PM
As long as your machines are connected to the same network (including the internet), all you need to do to connect them together is the IP address and port of your server (NAT could pose a problem if your server machine is behind a router with no public IP address and proper DMZ setup while trying to access it via the internet, but it shouldn't matter for local network).
Calling `Network.InitializeServer` will make one machine the server, while calling `Network.Connect` on the other machines (providing the correct IP and port of course) will make them the clients and connect them to the server. It's as simple as that, wireless network or not.
To make sure you know which is which you can use a simple script with a GUI label set to display the `Network.PeerType`.
var ServerIP:String = "127.0.0.1"; var ServerPort:String = "30000";
function OnGUI(){ if (Network.peerType == NetworkPeerType.Disconnected){ if(GUILayout.Button("Connect")) { Network.Connect(ServerIP,parseInt(ServerPort)); } if (GUILayout.Button("New Server")) { Network.InitializeServer(32,parseInt(ServerPort),false); } } else { if (GUILayout.Button("Disconnect")) { Network.Disconnect(); } } }
function Awake () { networkView.stateSynchronization = NetworkStateSynchronization.Unreliable; }
that is the code i have for networking, i made some little game and it would work on just my computer but when i tried to put the built game on a friends computer we couldn't see each other if it was running at the same time, and when i tried to put in my IP and port that didn't help at all, ins$$anonymous$$d it gave me a "failed to initialize network interface" error when i tried it on just my computer, then i put it on my friends and it didn't show me on his or him on $$anonymous$$e once again
Well, if you are on different networks, you will have to port forward on the server, see portforward.com
do i have to pay for that? because i am a student as i mentioned before, so i cant pay for stuff. and i am not sure but i think we have the same network... again i am a beginner coder, a virgin networker
No, port forwarding is something you have to do with your router. Basically it 'forces open' whichever ports you want, allowing information flow in and out. You might also need to set D$$anonymous$$Z to your server's machine's ip.
Enter your router's configuration (look at the manual or the internet for your specific model's address, just type it in your browser) and look for an 'advanced' tab, probably.