Remoting Chat Application

WEBINAR:On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

Concept

The application is designed using the .NET remoting framework 1.0. .NET remoting provides a very powerful framework for distributed applications. When you design a chat application, you need to maintain the state of the client at the server side. That means the server and clients must be in continuous contact. By using CAO (client activated objects), it is not possible to maintain state at the server side. Server-activated objects with singleton (a single server object serving all clients) design is the best methodology to develop a chat application. The application uses server-activated singleton object. A shared interface approach is used for communication between the server and client. This prevents the client from directly creating a server object.

Implementation

There are three projects in the application: ChatClient, ChatServer, and ChatMediator. ChatServer is a normal remoting server that runs on TCP (5678) and HTTP (8888) channels. The ChatMediator project is a common interface shared across client and server. ChatClient is the client that can connect to the server either by a TCP or HTTP channel. Following are the details of each project and how they work.

ChatServer

ChatServer is the simple remoting server. It also contains an internal class that derives from MarshalByRef and implements the common interface shared across client and server.

Remoting Chat Application

WEBINAR:On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

ChatMediator

This project contains two interfaces and one abstract class. One interface is a shared interface used by the client and server. Another interface is implemented by an Abstract class and used by server to send a message to the client. The interesting thing is the abstract class that will be implemented at the client side and generate events whenever a new user in joined, private chat is started, user left, and so on.

This architecture is implemented because when delegates are wrapped by some methods, the delegate needs full type information about the class that wraps the delegate. As abstract class is implementing an interface; the server sends message to all clients using the object of the interface. At the client side, when the message is received, an event is raised by the class (which is derived from abstract class) and handled in an actual Windows form application.

Remoting Chat Application

WEBINAR:On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

ChatClient

ChatClient is a Windows application. When ChatClient.exe is run, it first shows the splash screen that introduces the developer. When the user clicks connect, the application tries to the connect to server and when connected populates the list box with the current users online.

There is an EventClass class that derives from the abstract class and has delegates that are wrapped by ChatClient. Whenever EventClass receives message, it raises an event and ChatClient accordingly takes the necessary action.

Remoting Chat Application

WEBINAR:On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

When a user wants to begin a private chat with another user, a private chat window is automatically opened on the other user's side.

Private chat is a small winform that will send and receive messages from a single client. A hash table is maintained in ChatClient that contains a list of private windows. This will prevent the opening of a new private chat window for the same user. When the private chat window is closed, the hash table is updated.

About the Author

If you have run the application, you are already familiar with me. Still, I'll introduce my self. I'm Jayant D. Kulkarni, from Pune (one of the IT hubs in INDIA), Maharashtra, India. I'm working on .NET (C# 1.1, 2.0, ASP.NET 1.1, 2.0, VB.NET) for more than 1.5 years. I've total IT experience of nearly three years. Currently, I'm working with Mahindra-British Telecom, one of the leading telecom solution providers. I've BRAINBENCH certifications in C#, ASP.NET, ADO.NET, and .NET framework.

Please let me know your views, modifications you would like to see and suggestions at jdkulkarni@gmail.com.

Visit me at: http://jdkulkarni.tripod.com.

About the Author

Jayant Kulkarni

Dear Friends,
I'm from Pune and curently working with Symantec Corp. I'm having more than 7 years of exp in software field and have worked on areas like ASP.NET, C#, .NET remoting, web services, pocket pc applciations. I'm a brainbench certified software engineer in .NET framework, C#, ADO.NET and ASP.NET.
If you like any of my articles or you want to suggest some changes and improve the way I code, write articles feel free to mail me at: jayantdotnet@gmail.com