Photon -- Product Overview

Source: Internet
Author: User
Tags dotnet
ArticleDirectory
    • Reliable vs. unreliable

 

Product Overview on the client-side, photon supports various platforms. even though programming in C, C # And flash is very different, the basic workflow stays similar. in this online documentation we try to explain the concepts and background, while language specifics are left to the reference documentation per platform. on the client side, photon supports various platforms. The programming methods of C, C #, and Flash are different, but the basic workflow is similar. In this document, we try to explain its concept and background, and the detailed language section needs to refer to the reference documents of each language platform. Each photon client SDK comes with a fitting reference documentation for its platform and language. Each client SDK has a reference document for the relevant platform. Project setup project settings you need to include a single library to communicate with photon on the client-side. this is a different setup per platform. you need to include an independent library on the client. The settings for each platform are different.
    • DOTNET
Add a reference to the photondotnet. DLL in your DOTNET project to make its classes known. import the Lib's namespace with: Using exitgames. client. photon; reference photondotnet in the project. DLL, reference namespace using exitgames. client. photon
    • Unity3d
You need to import the photonunity3d. DLL into your project in unity. simply open a unity Project/scene, open an explorer and drag and drop. DLL from <SDK> \ libs \ debug \ into the editor. again, import the Lib's namespace with: Using exitgames. client. photon; you need to import photonunity3d. DLL to the project, open the unity Project/scene, open the resource manager from <SDK> \ libs \ debug \ drag and drop photonunity3d. DLL to editor and import the namespace using exitgames. client. photon; workflow the simplified lifecycle for any multiplayer game looks like this: the simplified life cycle of multiplayer games is as follows:
    • Connect to server
Connect to the server
    • Make RPC CILS
RPC call
    • Receive something
Receive data
    • Disconnect
Disconnect pretty simple. Let's have a look at each step, assuming you use C # And   Lite Application   . Very simple. Let's take a look at every step, taking lite as an example.
    • Connect to server
Actually, you do a little more than just connect in this step. In short: in fact, what you do is not just a connection:
    • Implement the interface Iphotonpeerlistener In one of your classes
Implement interfaces in your class Iphotonpeerlistener
    • Create a litepeer instance with your server's address
Create a litepeer instance and the address of your server
    • In your game loop, call Service About 10 times a second
The service is called every 10 seconds in your game loop.
    • Now call Connect To establish the connection. The application name shocould match one in the photonserver. config
Now establish a connection. This application Program The name must match in photonserver. config.
    • Your implementation if Peerstatuscallback Is called when the connection is ready or failed
You need to call this function when the connection is not connected. Peerstatuscallback
    • The returned status be Statuscode. Connect
The returned status is Statuscode. Connect The peer instance provides you with some methods to talk to photon. It does not have its own thread. It updates when you call   Service   Instead. this will keep the connection alive peer instance provides some methods to access photon. It does not have its own thread and is updated when you call the service, and keep the connection we assume that photon is running the "Lite" application, which it does by default. let's assume that photon runs Lite. The following is the default situation.
    • Make rpc cils rpc call
After connecting, the client can call methods in the lite application just about anytime it needs. the methods available as "Remote Procedure Call" are called operations. after the connection, the client can call the lite application method at any time. Such a Remote Procedure Call is called the operation CILS are asynchronous and won't block your game. they are queued internally until you intently send something by calling   Sendoutgoingcommands . There will be a short delay until the result is wrongly ed. These results are defined per operation and are not used at all sometimes. Operation calls are asynchronous and will not block your game. They queue internally until you need to send them through Sendoutgoingcommands Send. Only a short delay is required to receive the results. These results are defined as operations and not all the time periods are used.
    • Call Opjoin With any room name to get into a game
Call Opjoin Can join the game
    • Wait for the callback: Operationresult With OpcodeLiteopcode. Join
Wait for the callback to include Opcode : Liteopcode. Join Of Operationresult
    • Send any hashtable with content by calling Opraiseevent. Other players in the room will receive events.
By calling Opraiseevent Send hashtable with content. Players in other rooms will also receive related event information. Joining a room and raising events in it is provided (server side) by the lite application logic we use in this sample. you can use other applications and implement your own operations. this is an example of joining a room and triggering an event based on the logic of the lite application. You can use other applications and perform your own operations.
    • Receive something receives data
In the previous step you already ed an operation result. we differentiate those from other incoming messages, so called events. lite will forward the event you raised to others in a room. in the previous step, you have received the operation result, which is different from the information from other places, so it is called an event. Lite will send this event to others in the room.

Processing ing events will call Iphotonpeerlistener. eventactionEvcode Will match the one you used in OpraiseeventCallIphotonpeerlistener. eventactionReceive events,EvcodeWill be used with yourOpraiseeventMatch the client library will internally queue named Ed packages, so your game decides when to use them. Eventaction Is called by your callto Photonpeer. ServiceThe client queues the received packets internally, and it is up to your game to decide when to use them.Photonpeer. ServiceTo callEventaction

    • Disconnect
When a client is closed, the best is to disconnect. that's nice, but not a must-have as a timeout will disconnect clients that don't answer anymore. when the client is closed, it is best to disconnect, but not as timeout.
    • To close the connection: Call Disconnect
Close connection: Call Disconnect
    • Check "disconnect" return in Peerstatuscallback With StatuscodeStatuscode. Disconnect
Check "Disconnect ", Peerstatuscallback The returned value is Statuscode : Statuscode. Disconnect
    • now the client can stop calling service
Now the client can stop calling the litepeer versus photonpeer litepeer and photonpeer aside from the litepeer, the client libraries also include a photonpeer which cocould be used. the photonpeer has the bare minimum of API needed for photon. it is the base for litepeer, which adds operations like "join", "leave" and "raiseevent", which are available with the lite application. in addition to litepeer, the client also contains a photonpeer that can be used, photonpeer Photon has only limited APIs. It is the foundation of litepeer. In lite, litepeer adds "join", "leave", and "raiseevent. Reliable UDP under the hood, photon clients and servers send operations and events via UDP. this guarantees low overhead, flexibility and performance but is unreliable by definition. at the underlying layer, the photon client and server send operations and events through UDP, which ensures low overhead, flexibility and performance but is defined as unreliable. Within the UDP packages, photon uses a thin binary Protocol to enable aggregation, ordering, detection of packet loss and more. it is based on enet and used in similar form on client and server. in UDP packets, photon uses a simple binary protocol for aggregation, sorting, and packet loss detection, it is a enet-based so called "commands" are used to transfer the payload, such as operations. on the client side, photon gives you full control of when commands Are put into a UDP package and send. The so-called "commands" is used to pass this load, such as operations. On the client side, the photon Control Command sends as a result in the form of a UDP packet, the API also limits des methods that manage the connection to the server. basically, there are two "Layers": the "Command layer" and the "Operation layer": Therefore, APIS also include methods for managing server connections. Basically, they are composed of two layers: "command layer" and "operation layer"
    • Command layer: Manages the communication protocol to establish and maintain communication.
Command layer: manage communication protocols to establish connections and maintain communications
    • Operation layer: Gives access to rooms, events and custom operations. Client Side, methods of this layer are prefixed with "op ".
Operation layer: used to access rooms, events, and custom operations. On the client side, this method is prefixed with "op" reliable. unreliable reliable to unreliable with photon's underlying protocol, everything that's sent guest SS can be made flagged as reliable or unreliable. the operation request is not changed by this though, only the command that's used. the bottom-layer protocol of photon can be marked as reliable or unreliable. The request operation cannot be changed only when the command is used. Photon keeps track of the ordering. even unreliable commands are synchronized/sequenced within the order of reliable commands. so an unreliable Command, which was sent after a certain reliable command, will also be dispatched after the reliable command was dispatched (even if that command was delayed ). photon keeps track. unreliable commands are synced with reliable commands, so an unreliable command is sent after a reliable command, it will also be dispatched after reliable commands are distributed. Operations and events that are sent as unreliable might get lost. as example, this is no problem for position updates, which are quickly replaced. on the server side, operations that are supported ed unreliable, shocould not create a result: the client can not operated CT that the operation even reached the server. operations and event sending cannot be lost. For example, location update is not a problem and the update will be replaced soon. on the server, the client does not expect the operation to arrive at the server. Connection and timeout connection and timeout the client has two rules to define a timeout: the client has two rules to define Timeout:
    • Retries: A reliable command is sent multiple times to be acknowledged, each time the interval between retries gets longer, depending on general rountrip times. If the number of retries reaches a limit (in DOTNET: Sentcountallowance), This causes a disconnect.
Retry: a reliable command will be sent multiple times for confirmation. The interval of each Retry is longer. According to the unified region time definition, if the number of retries reaches a limit, the connection will be disconnected.
    • Disconnecttimeout: This defines a maximum number of milliseconds, before a reliable command must be answered. This is independent of the retry counting. In DOTNET, the setting is: Disconnecttimeout.
Disconnection Timeout: This defines the maximum number of milliseconds between which a reliable command must reply, which is independent of the retry count and is set Disconnecttimeout The settings are described in more detail in the client API documentation. For more information, see the client documentation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.