真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

unity服務(wù)器PhotonServer學(xué)習(xí)筆記

(一)服務(wù)端
新建類庫(kù)
引用:ExitGamesLibs,Photon.SocketServer,PhotonHostRuntimeInterfaces

平和網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)從2013年開(kāi)始到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。

ApplicationBase

using chatServer.Properties; using Photon.SocketServer; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace chatServer { ///

/// 繼承applicationBase的類是入口程序,也是啟動(dòng)程序 /// public class ChartServer : ApplicationBase { /// /// 客戶端連接到這個(gè)Server端調(diào)用 /// /// /// protected override PeerBase CreatePeer(InitRequest initRequest) { return new ChartPeerBase(initRequest.Protocol, initRequest.PhotonPeer); } /// /// Server端啟動(dòng)時(shí)調(diào)用 /// protected override void Setup() { } /// /// 這個(gè)Server端停掉時(shí)調(diào)用 /// protected override void TearDown() { } } }

PeerBase

using Photon.SocketServer; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using PhotonHostRuntimeInterfaces; namespace chatServer.Properties { ///

/// 用來(lái)和客戶端進(jìn)行通信 /// class ChartPeerBase : PeerBase { public ChartPeerBase(IRpcProtocol protocol, IPhotonPeer unmanagedPeer):base(protocol,unmanagedPeer) { } protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail) { throw new NotImplementedException(); } protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { throw new NotImplementedException(); } } }

設(shè)置輸出
在下載好的sdk目錄下新建文件MyChartServer,并在文件下新建bin目錄

項(xiàng)目-chatserver屬性(Alt+F7)-生成-輸出路徑為ExitGames-Photon-Server-SDK_v3-4-31-10808deployMyChartServerbin

配置文件
ExitGames-Photon-Server-SDK_v3-4-31-10808deploybin_Win64配置PhotonServer.config文件下

Application Name=”Lite”和”LiteLobby”間加入新的Application,配置如下

(二)客戶端
新建控制臺(tái)程序
引用Photon3DotNet

using ExitGames.Client.Photon; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PhotonChatServerClient { class ChatServerListener : IPhotonPeerListener { public bool isconnect = false; public void DebugReturn(DebugLevel level, string message) { } public void OnEvent(EventData eventData) { } public void OnOperationResponse(OperationResponse operationResponse) { } public void OnStatusChanged(StatusCode statusCode) { switch (statusCode) { case StatusCode.Connect: isconnect = true; Console.WriteLine("Connect"); break; } } } class Program { static void Main(string[] args) { ChatServerListener listener=new ChatServerListener(); PhotonPeer peer=new PhotonPeer(listener,ConnectionProtocol.Tcp);//第二個(gè)參數(shù)為選擇的協(xié)議 peer.Connect("127.0.0.1:4530", "ChartServer");//連接服務(wù)器,4530為config文件指定協(xié)議所對(duì)應(yīng)的端口號(hào),Chartserver為之前的服務(wù)端應(yīng)用 while (!listener.isconnect)//判斷是否建立連接 { peer.Service();//這個(gè)調(diào)用完才能向服務(wù)器發(fā)起請(qǐng)求 } } } }

(三)運(yùn)行客戶端服務(wù)端,完成連接
(四)客戶端發(fā)起請(qǐng)求
修改之前的客戶端

using ExitGames.Client.Photon; using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PhotonChatServerClient { class ChatServerListener : IPhotonPeerListener { public bool isconnect = false; public void DebugReturn(DebugLevel level, string message) { } public void OnEvent(EventData eventData) { } public void OnOperationResponse(OperationResponse operationResponse) { } public void OnStatusChanged(StatusCode statusCode) { switch (statusCode) { case StatusCode.Connect: isconnect = true; Console.WriteLine("Connect"); break; } } } class Program { static void Main(string[] args) { ChatServerListener listener=new ChatServerListener(); PhotonPeer peer=new PhotonPeer(listener,ConnectionProtocol.Tcp); peer.Connect("127.0.0.1:4530", "ChartServer");//連接服務(wù)器 while (!listener.isconnect) { peer.Service(); } Dictionary dict=new Dictionary(); dict.Add(1,"username"); dict.Add(2,"password"); peer.OpCustom(1, dict, true); while (true) { //死循環(huán)防止程序終止 peer.Service();//發(fā)出去 } } } }

(五)服務(wù)端響應(yīng)
修改之前的服務(wù)端PeerBase

/// 當(dāng)客戶端發(fā)起請(qǐng)求時(shí)調(diào)用 /// /// /// protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { Dictionary dict = new Dictionary(); dict.Add(1,"siki"); OperationResponse response=new OperationResponse(1,dict); SendOperationResponse(response, sendParameters); } }

(六)客戶端獲得服務(wù)端的響應(yīng)

///

/// 得到服務(wù)器端的響應(yīng) /// /// public void OnOperationResponse(OperationResponse operationResponse) { Dictionary dict = operationResponse.Parameters; object val = null; dict.TryGetValue(1,out val); Console.WriteLine("getserver"+val.ToString()); }

(七)unity客戶端
目錄Plugin下引入sdk/lib/Photon3Unity3D.dll

using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using ExitGames.Client.Photon; using UnityEngine; public class PhotonServerEngine : MonoBehaviour ,IPhotonPeerListener { private PhotonPeer peer; private bool isconnect = false; void Start() { peer = new PhotonPeer(this, ConnectionProtocol.Tcp); peer.Connect("127.0.0.1:4530", "ChartServer");//連接服務(wù)器 } void Update() { peer.Service(); } void OnGUI() { if (isconnect) { if (GUILayout.Button("Send")) { Dictionary dict = new Dictionary(); dict.Add(1, "username"); dict.Add(2, "password"); peer.OpCustom(1, dict, true); } } } public void DebugReturn(DebugLevel level, string message) { Debug.Log(level+":"+message); } public void OnEvent(EventData eventData) { } public void OnOperationResponse(OperationResponse operationResponse) { Dictionary dict = operationResponse.Parameters; object val = null; dict.TryGetValue(1, out val); Debug.Log("getserver" + val.ToString()); } public void OnStatusChanged(StatusCode statusCode) { switch (statusCode) { case StatusCode.Connect: isconnect = true; Debug.Log("Connect"); break; } } }


分享題目:unity服務(wù)器PhotonServer學(xué)習(xí)筆記
網(wǎng)頁(yè)地址:http://weahome.cn/article/chdpoi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部