- Home /
Network server client
Hello
I'm new to network programming(and mostly unity to, but done a lot of .net c# programming) and have done a small program that use, client server RPC programming. Now i need to know a little more about how to make a game where i don't use a dedicated server(meaning a player will host the game other players will then join him). My biggest problem atm is that, i cant rely on my users to have a router with Upnp + they dont know how to port forward either.
I've have been searching for hours and hours on Google but have yet to find a tutorial or something similar that will help me.
On my search i found a method called NAT traversal, and have been told it can help me sort my problems with port forward and so on. But i don't really know how to implement this method in my project.
If anyone out there can help me, to move forward with learning more about network programming, ill be more the happy to try it out.
there is a parameter for useNAT in Network.InitialiseServer() but I have never managed to implement it successfully.
Answer by Bunny83 · Sep 12, 2012 at 05:19 PM
Unity uses RakNet for networking. This network engine provides a Nat-punch-through technique which allows two or more clients to direct-connect to each other by using a master-server which acts as initial connector between clients. Officially it's called "UDP hole punching".
While it works with a lot of Nat-routers, it's not possible with all types. It's not a bug, it's more because there are many different NAT-routers out there and there's no reliable standard. Mainly because the NAPT-technique is already a "misuse" of the port number in the UDP / TCP protocol. Actually the routers that are capable of NAT punch through are "less safe" ;)
So there is no reliable way to get around the NAT problem, but the NAT punch through should work in most cases. If not there's not much you can do beside checking for Upnp and asking the user to manually forward. On the other hand all games have those problems. Most eleminate those problems by providing dedicated servers, but as small company that's not always an option.
Well that makes me sad, but i did know that i might not be possible to find a solution that would always work when i don't have a dedicated server. Thx for the answer, i need to decide now, if i should get a server or not. cause the idea of the game I'm making is that my clients need to be 100% able to play it on any computer they install it on.
Out of curiosity - on the server you would you need to run a unity file to connect and manage clients?
Well, yes. If you want to run a dedicated server, you have to run your game / application on the server as well. You can start Unity in batch-mode so the renderers are disabled. There's no graphical output on the server in that case.
When you just want to host a masterserver you just need to run the masterserver build which you can download for free.
It depends on the type of game and on what kind of networking you need. Raknet is ment for real-time networking. If time isn't that important you could use a normal webserver for communication. It's of course a bit slower, but you could use any free-hosted webserver as long as you stick to their terms of service. Some doesn't allow pure file hosting or chat-proxy usage, but i guess if you host a website as well it should be no problem ;)
It's a FPS game so real-time is important, i did stumble over Raknet on my Google searches. You say that its already build into unity?
Answer by Jesse L · Sep 30, 2012 at 03:23 AM
I can't find thread so posting random question. I am based out of Chicago and have finished prototype with contract programmers. Looking for Chicago based programmer for potential partnership.
Jesse jesseflangille@gmail.com
Not an answer! This is a Q&A site about Unity. Questions should be about development questions about Unity that are of interest to at least one other Unity developer.
Read the FAQs
Such requests should be posted on the Unity Forums in the Collaboration section
Answer by BlackHunter · Sep 11, 2012 at 07:12 PM
D:/Program%20Files/Unity/Editor/Data/Documentation/Documentation/Manual/index.html view it
Thx for the replies, i have been looking into http://unity3d.com/support/resources/example-projects/networking-example, before i posted here, and for someone new to unity i think it needs some documentation to go with it.
Another thing is that all the examples seems to have the port forward problem where the one starting the server needs to forward hes/her port for others to join over Internet(that's just from what I've seen, tell me if I'm wrong)
Your answer