An App From Scratch

This tutorial will try to help you understand how to build an application from scratch.

This tutorial has nothing to do with Photon Chat product. It is just a very basic and simple demo sample meant as an example of how to start a Photon Server application.

Build a Simple Chat Server In 10 Minutes.

Note: We assume you have followed the steps in "Photon in 5 Minutes" and have a locally running Photon Server.

This tutorial is thought as a first step in understanding the basics of the main concepts in Photon Application and Peer.

  • Download the Photon Server SDK and unzip it.
  • Using Visual Studio, create a new class library project ChatServer.
  • Add references to ExitGamesLibs.dll, Photon.SocketServer.dll and PhotonHostRuntimeInterfaces.dll

Now, create a new class ChatServer that inherits from Photon.SocketServer.ApplicationBase:

Create a new class ChatPeer that inherits from Photon.SocketServer.ClientPeer:

Return a new instance of ChatPeer at ChatServer.CreatePeer:

The ChatServer assembly will be loaded by Photon native core on the Default Photon instance. Thus, the server configuration file, PhotonServer.config, should contain the proper definition of that application. The following snippet illustrates an easy way to do this:

This configuration requires that the server binaries are located under deploy/ChatServer/bin and that class ChatServer does not belong to a namespace. For more information about server configuration please refer to the respective documentation page.

Create a new console project for a chat client. Add reference to Photon3DotNet.dll to the new project. Client code should read as follows.

If we now start the server the client will be able to connect and to send text messages. The server logic to process these text messages is still missing. To verify that the message was received we answer with an OperationResponse at ChatPeer.OnOperationRequest.

The chat client should now be able to print the event code and the chat message.

Next thing we want to do is to receive the chat messages on other clients. We implement the receiver using a publish/subscribe pattern.

If you now start two clients both will be able to exchange messages. Do not forget to start Photon server or to restart it with the new configuration. Go to the documentation page if you have troubles with it.

 To Document Top