Unity Networking

Hello, in mmorpgs there are public maps, so i dont think Network.InitializeServer command is useful as the server is always online. So how can i connect and show the players’ position etc?

mmorpgs needs a lot of servers to handle all the player that wants to connect to the game. Those servers have to be run by the game creator, in this case by you. This / those server(s) has to run 24 / 7 so everyone can connect to them when ever they want.

Runing a powerful server 24 / 7 costs a lot of money that you have to pay. That’s the reason why most MMOs have a monthly fee the players have to pay.

To sum up in a sentence:
You always need a server somewhere on the internet in order to connect to it.

Unity’s build in Network engine isn’t ment for many connections. If you plan an mmo you either have the hardware capacities at your company to run the servers on your own or you need to hire servers by a hosting company.

One of the most popular mmo servers are SmartFox servers

edit
Ok here’s a crash course of “The Internet”:

The Internet

The internet is actually nothing but a network. The internet doesn’t contain things, it just connects them. Every participant which is connected to the internet is more or less equal. Any peer in this huge network can host any kind of server to wich others can connect to.

Domain Name System / Service (DNS)

To connect to a server / service on a certain peer you need to know the IP address of this participant to send your packages to the right target. For this purpose we have the DNS system. This is a special server which is usually hosted by the internet service providers(ISP) and can be used to search for a certain domain name and it will return the linked IP address if the name exists.

Again, this is just a server which could be run by anyone that is connected to the internet. But in order for someone to use / connect to your server he needs to know the IP address. The “official” DNS servers are, as stated above, hosted by your ISP and when he connects you to the internet he’s telling you the IP address of the DNS server you should use. This wouldn’t prevent you from using a different DNS server if you know the IP of it.

The usual user doesn’t have a domain name since he’s just a client which want’s to connect to other servers. When you connect to a server you tell the server your IP address since in every packet you send contains the ip address to which peer this packet should be transferred and from which peer it’s coming from.

What is a Server

If you talk about server it can have different meanings depending on the context. Some refer to a Server-machine, a special kind of computer which is optimised to run server processes. Others refer to an operating system that is optimised to run server processes. Mainly all discussions end at the actual “server” which is just a piece of software which uses the OS and the hardware to provide a certain service for other clients. The server “serves” a service to it’s customers, the clients.

A example i take my own PC. I run several servers on it: A webserver (HTTP), a MySQL server, an FTP server and sometimes a Minecraft bukkit server ;). Client and server doesn’t have to be on different machines. I can connect to my own webserver by open my browser and connect to my server. The browser is the client

Peer to Peer

A peer to peer connection means that two or more peers / participants act as server and / or client at the same time. Each peer actually “connects” to each other peer he needs / wants to communicate with. This system is great when you have to transfer a lot individual data from one peer to another. The available bandwidth is used very effectively. The downside is that you can’t control who talks with whom. Most games need to validate and syncronise states between each other. Since each peer can send different data to others no one can validate which data is correct.

Another problem is due to the nature of the internet it’s possible that user A can connect to B but not reverse. In a game with 3 or more players this would be a nightmare.

Client-Server-model

Beside peer to peer connection the mostly used communication way is the client-server-model. Here all clients connect to one server and all communication goes through the server, The server can vaildate data sent by clients and distributes it to the other clients when needed. The downside is that the server machine has the highest network load since everything goes through it.

Packet-based / Connection-based

The internet or to be more precise the Internet Protocol is packet based. So it works like our mail system. You write a letter, put your address at the top left and the address you want to send the letter to at the bottom right. You just throw the letter in a mailbox and pray that it arrives at the destination. The problem is like in the mail system letters or packets can get lost on it’s way. You don’t know if the packet has arrived or not and the destination side doesn’t even know that you’ve send one.

That’s why connection based protocols like the Transmission Control Protocol has been invented. It’s a protocol that builds on top of the IP protocol, but it includes some special information so the other side knows when a packet is missing. Those connections are just “virtual connections”. When you “connect” to a server both sides just remember this “connected” state, that’s all. Each packet is acknowledged with an ack-packet. That’s why those connection based protocols are much more reliable. HTTP, which is used to request a website, is a protocol that builds on top of TCP.

The downside of TCP is that it’s slower and has more overhead than connectionless protocols. Which protocol to use depends on the kind of data and the importance of the information. Most FPS games use a connection less, packet based protocol to reduce the response time. The position of players is sent several times a sec, it doesn’t matter if you miss one update.

Unity’s builtin Network engine

Unity uses RakNet. Raknet uses the UDP protocol which is the most commonly used connectionless protocol. However RakNet implements sort of transmission controlling in the userdata that a packet is carrying if required. That allows Raknet to send unreliable packets or reliable when needed. RPCs for example are send reliable. It makes no sense to execute an RPC and half of the clients didn’t receive it.

In Unity a player can be server or client. You can’t be both at the same time. Also you can only connect to one server at a time. The player that starts the server locally hosts the game and all other clients have to connect to his PC. Things like NAT routers and Firewalls can prevent clients from successfully connecting to the server.

If the server is hosted by a player all other clients can’t continue playing when the server player quits and closes his server. That’s why a lot games use dedicated server. A dedicated server is just a server without a player that plays on the server machine. All players connect as clients.

Dedicated servers also have to be hosted by someone. If you want it to be available 24 / 7 you have to keep it running day and night.

Well there are a lot other things that might be important or “good to know”, but i guess i’ll just stop here. If you really planning an MMO, get familiar with the technology you’re going to use :wink: