- Home /
Simple create/connectto server without Masterserver and joining by IP
Hey! I am quite new to programming and fail to understand many concepts relating to Networking.
As I assume Masterserver is like a database which registers and returns a list of all your Internet games(like a server browser in CS, CS:S, TF2 and so on), which other people can see and connect to. It also allows people without public IPs to be seen and be reachable for other people.
I have a question: is it possible to do without Masterserver at all? Is there a possibility that a person can create his own server with a mouse click; and another person be able to connect just by inputting IP address and a Port? (Like it is done in Terraria). If yes: what is the code to instantiate and/or connect to a server?
Thank you very much for help!
Everyone has a public IP and the $$anonymous$$aster-Server actually acts like a gateway for connections, rather than just showing them to you.
To answer your question, you should take a look at the documentation of the Network
class.
as far as I know, not everyone has a Public IP, some Internet providers even charge for that kind of servers. $$anonymous$$aybe I am wrong?
The way the internet works is by sending information back and forth between computers on one giant network. Your public IP is how other people connect back to you. Without it, it's a one way, useless connection. I might be wrong, but I'm pretty sure that if you don't have a Public IP then you're not technically connected to the internet
@Fewpwew130: You are correct, the masterserver itself is just a database where servers can register themselfs so others can find the server. However the masterserver also contains a facilitator which helps the users to connect to each other by exchanging ip and port information between clients so they might be able to perform NAT-punchthrough.
Every user of the internet needs a public IP address, otherwise a user can't receive anything. However nowadays the users device usually doesn't have a public IP but share the one the router got from your ISP. That's why the router has to remember / decide which information belongs to which local client. This is done with NAT (actually NAPT). The router can distinguish the different local clients by the used local port. NAT only works when the local user initiate the connection. That way the router can automatically "open" the correct public port to route the returned data to the correct client.
Without a port-forwarding-rule in your router you usually can't direct connect two clients which are both behind a NAT. NAT-punchthrough actually uses a security vulnerability of the router to "punch a hole" into the router. Since not all routers are that "weak" it's quite possible to fail. In general it's always more reliable to configure a port forwarding in the router. That's however not always possible if you have no access to the router like when using mobile internet (3G ...).
Benproductions1 and Bunny83, thank you very much for clarifying =)
Answer by Bunny83 · Jan 24, 2014 at 11:22 AM
Sure it's possible. You always start a server by using Network.InitializeServer and others can use Network.Connect with an ip or domain name and a port. The Masterserver is completely optional. However keep in mind that the one that hosts the server need to be reachable from outside, so he/she needs to port-forward your server port.
Bunny83, thank you for a quick answer! Can I use Hamachi to avoid this problem? Or Hamachi doesn't give 100% guarantee that my friends will see me?
Hamachi is basically a hacky way of faking a ethernet connection. So yes, it should work.
right, Hamachi opens a VPN tunnel and virtually connects multiple users in a private network. As far as i know it also tries NAT punchthrough for connecting clients, if it's not possible your traffic goes through the hamachi servers.
The problem with Hamachi is it's slow compared to a direct connection. It's usually not the best for playing high traffic games that require a low latency.