茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1675135 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
HoneyMoon_Day2_00139.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2014/11/26 4:12:46

構建自己的 Unity 網絡服務器 Building the Unity Networking Servers on your own

Date:2013-06-25 03:29

The source code for all the individual networking servers can be downloaded from the Unity website. This includes the connection tester, facilitator, master server and proxy server.

可以從 Unity 網站下載創建服務器所需的 source code,包含連接測試器、facilitator、主服務器代和理服務器。

All source packages include the RakNet 3.732 networking library which handles the basic networking functions and provides plugins used by the networking servers.

所有源碼包包含了可以處理基本網絡功能的 RakNet 3.732 庫文件,也提供了可以被網絡服務器所使用的插件。

The packages include three different types of project files, ready for compilation:

這個包,包含了三種不同類型的可編譯的項目文件:

  • An Xcode 3.0 project for Mac OS X
  • A Makefile for Linux and Mac OS X

  • A Visual Studio 2008 solution

The Xcode and Visual Studio projects can just be opened, compiled and built. To build with the Makefile just run "make". It should work with a standard compilation setup on Linux and Mac OS X, if you have gcc then it should work. On Linux you might need to install the ncurses library.

The Xcode 和 Visual Studio 項目可以被打開,編譯並創建帶有 Makefile 的項目,需要運行"make"指令進行創建。 這些都可以在 Linux 和 Mac OS X 上的標準編譯平台上正常工作。 如果採用 gcc 進行編譯,Linux 平台需要安裝 ncurses 庫。

Structure 結構

The Master Server 主服務器

The Master Server uses an internal database structure to keep track of host information.

主服務器使用內部數據結構來跟蹤主機的訊息。

Hosts send messages with the RUM_UPDATE_OR_ADD_ROW message identifier and all their host information embedded. This is processed in the OnReceive()
function in the LightweightDatabaseServer.cpp file. This is where all message initially appear and therefore a good place to start if you want to trace how a message is processed. A table is created within the database structure for each game type which is set when you use MasterServer.RegisterHost function. All game types are grouped together in a table, if the table does not exist it is dynamically created in the CreateDefaultTable() function.

主機發送帶有 RUM_UPDATE_OR_ADD_ROW 標識符的消息並嵌入主機訊息,這些消息在 LightweightDatabaseServer.cpp 文件中的 OnReceive() 函數中被處理。 所有的消息被處理的地方,也是開始跟蹤消息如何被處理的好地方,當使用 MasterServer.RegisterHost函數,將會為每一個遊戲類型創建一個數據庫表格。 所有類型的遊戲被組織在這個表格裡,如果表格不存在,可以在調用 CreateDefaultTable() 函數時動態生成。


The host information data is modified by the master server. The IP and port of the game which is registering, as seen by the master server, is injected into the host data. This way we can for sure detect the correct external IP and port in cases where the host has a private address (NAT address). The IP and port in the host data sent by the game server is the private address and port and this is stored for later use. If the master server detects that a client is requesting the host data for a game server and the server has the same IP address then he uses the private address of the server instead of the external one. This is to handle cases where the client and server are on the same local network, using the same router with NAT addresses. Thus they will have the same external address and cannot connect to each other through it, they need to use the private addresses and those will work in this case.


主服務器可以修改主機的訊息數據,被主服務器所看到的已註冊的遊戲的 IP 和端口被灌入到主機數據裡,這樣我們可以確保,當主機使用私有地址(NAT 地址),也可以檢測其正確的外部 IP 和端口。 被主服務器所發送的 IP 和端口將會被存儲以備後用。如果主服務器檢測到客戶端,正在請求一個遊戲服務器的主機數據,而這個服務器同 Master Server 具有相同的IP地址,這時就會轉而使用服務器的私有地址,而不是外部的那個。 這是處理客戶端和服務器在同一個本地網絡的,使用相同的帶 NAT 地址的路由器情況。他們具有相同的外部地址,因此,無法通過它來連接對方,在這種情況下他們需要使用私有地址。

Clients send messages with the ID_DATABASE_QUERY_REQUEST message identifier and what game type they are looking for. The table or host list is fetched from the database structure and sent to the client. If it isn't found and empty host list is sent.

客戶端發送帶有 ID_DATABASE_QUERY_REQUEST 標識符的消息來請求查找的遊戲類型。 從數據庫結構中取出表格或者主機列表並發送到客戶端,如果沒有找到,將發送空的主機表格。

All messages sent to the master server must contain version information which is checked in the CheckVersion()
function. At the moment each version of Unity will set a new master server version internally and this is checked here. So if the master server communication routine will change at any point it will be able to detect older versions here and possibly refer to another version of the master server (if at all needed) or modify the processing of that message to account for differences.

所有發送到主機的消息包必須包含版本訊息,並在 CheckVersion() 函數中被檢查。 每一個 Unity 版本都會設置一個新的內部主服務器版本並在這裡被檢查。 因此,如果主服務器通信程式在任何時候被改變,它將能夠檢測到舊版本同時可能會參考主服務器的其他版本(如果有必要的話)或者修改消息的處理過程去應對差異。

The Facilitator

The facilitator uses the NAT punchthrough plugin from RakNet directly with no modifications. This is essentially just a peer listening on a port with the NAT punchthrough plugin loaded. When a server and a client with NAT addresses are both connected to this peer, they will be able to perform NAT punchthrough to connect to each other. When the
Network.InitializeServer uses NAT, the connection is set up automatically for you.

Facilitator 直接使用了 RakNet 的 NAT 網絡穿透插件。 本質上就是加載 NAT 網絡穿透插件來偵聽一個端口。當一個帶有 NAT 地址的服務器和客戶端都在連接這個端口時,他們可以執行網絡穿透去連接到對方.當調用 Network.InitializeServer使用 NAT,連接會被自動設置。

頁面最後更新: 2011-02-04


Building the Unity Networking Servers on your own 构建自己的Unity网络服务器 - Unity圣典
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|