Remoting

Singleton Remote Server Explained

1. Introduction

In the previous article, we saw about the server activated Single Call remote object. Also remember, each call to the server will create a new remote object in the ‘Single Call’ technique. In this article, we will see how the Singleton Remote Objects work.

The Singleton Remote Server Example here does not call for a big explanation. Because, we are already aware with the Remoting by the past article on the Remoting topic. You can read remoting in details in this link: Basics of Remoting so that this article goes easy.

2. Singleton Remote Objects – Server Activates

In this technique also, Remote Server creates the object and keeps that in the server’s Remote Object Pool. Unlike the Single Call technique, here only one object is created and maintained in the pool. All client applications access the same remote object. That is why we call this remote object as Singleton Remote Object.

To better understand the usage of Singleton Remote object, we can create a simple application by following the direction provided in the base article.

3. Singleton Remote Server & Client

As already told, there is not much explanation required on the coding side. In the coding side, we need to say to the server that we want to register the object as Singleton Remote Object. That is all. The server application will take care of the remaining. Below is the code change that makes the Remote Object as Singleton.

Next, we deploy the Server on one machine and run the client application from a different machine to see how it works. Otherwise, we can run multiple instances of client applications in the same machine. Below is the Screenshot of a server and two clients:

Client and Server of Singleton Remoting

Client and Server of Singleton Remoting

In this example, all the clients have access to the ‘ RegVotes’ Remote Object. We register this object as Singleton Remote Object and hence the server holds a single copy. All the clients share this single object living in the server.

As a client, one can select a voting option and click the Vote Now button. The server returns the average rating based on the previous client voting received by it.

4. Search Tags for the Attached Example

Once you download the example, you can open the solution file which you can find inside the ‘SingletonServer’ folder. You can use the below tags to search the projects:

  • //Client
  • //Server

You will get the entire code changes which is quite equal to the past Single Call example. This example differs only in the place where we register the object using RegisterWellKnownServiceType API.

Download Source Code from Google Drive: Singleton Remote Server Example

Advertisements

This site uses Akismet to reduce spam. Learn how your comment data is processed.