Photon用戶端API

來源:互聯網
上載者:User

1:實現IPhotonPeerListener介面用來接收訊息。

介面中有如下4個方法:

摘要:當photon伺服器派發事件到用戶端時被調用。

void OnEvent(EventData eventData);

摘要:Callback method which gives you (async) responses for called operations.

 void OnOperationResponse(OperationResponse operationResponse);

摘要: OnStatusChanged is called to let the game know when asyncronous actions finished  or when errors happen.

 publicvoidOnStatusChanged(StatusCode
statusCode)

2.Main Part:

    建立一個listener執行個體 :var
listener =
new
Program();

 建立一個photonPeer執行個體 :var
peer =
new
PhotonPeer(listener, ConnectionProtocol.Udp);

串連photon伺服器peer.Connect("localhost:5055","Lite");

調用peer.Service();觸發網路傳輸,派發訊息。

3.Operations :通過請求(request)和響應(response)調用遠程程式,它是我們的術語遠程調用。

就是在伺服器端實現的方法在用戶端被調用。operations是運行在伺服器端的應用程式。

Events :發送到用戶端的訊息和通知。和operation不同的是,events來自外部,伺服器或者是其他用戶端。

用戶端通過OnEvent回呼函數響應。例如有玩家加入房間,該玩家會發送一個請求使用OpCustom方法來調用operation,並且使用一個Dictionary來傳遞參數。

peer.OpCustom(( byte )LiteOpCode.RaiseEvent,
opParams, 
true );房間裡面的其他玩家會接受到一個事件

 
         
Dictionary<Byte,
Object>opParams = 
new Dictionary<Byte,Object>();              opParams[( byte )LiteOpKey.GameId]
"MyRoomName" ;              peer.OpCustom(( byte )LiteOpCode.Join,
opParams, 
true );

注釋:

當statuscode == StatusCode.Connect 時調用peer.Opcustom。

建立一個hashtable(opParams),裡麵包含了參數。調用peer.OpCustom,參數(OperationCode和OperationParams)。

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.