Track Multiple Clients with a Singleton

Problem

You want to allow multiple clients to communicate with each other through a single server.

Solution

Create a server-side singleton object that tracks all the currently available clients on the network. The server should store a proxy object for each client in an in-memory collection.

Discussion

When you create a remote object that uses singleton activation mode, only a single instance of it will be created. All the clients that use this remote object will access the same instance. This means that the remote object can store some information that will be shared among all users (such as a list of connected clients). It also means that you’ll need to craft thread-safe code using the techniques presented ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.