Home > Articles > Programming > Windows Programming

Creating a .NET Instant Messenger

  • Print
  • + Share This
Instant messaging is sweeping the world, and is rapidly replacing email as the preferred electronic communications means. Behind this phenomenon, however, is a rather simple technology, which Chris Payne discusses (with step-by-step building instructions).
From the author of

Instant messaging is sweeping the world—it is rapidly replacing email as the preferred electronic communications means. Behind this phenomenon, however, is a rather simple technology, especially with .NET's new programming paradigm. This article will give some background on the technologies needed to build an instant messenger, as well as build a simple one step by step.

The Network

The first thing that comes to mind when thinking about an instant messaging application (IM) is the Internet; after all, to send an instant message, you need to deal with a network. The System.Net namespace in the .NET Framework contains all the classes you'll ever need to handle network requests of any type (and for IM, you don't need many).

.NET introduces pluggable protocols, which is a way to create an application that can handle any type of Web request using only one class. .NET automatically determines the type of network traffic that is going on, and adjusts appropriately—taking a lot of work away from you, the developer.

In this article, we'll look at a few classes in the System.Net.Sockets namespace, which provides a more sophisticated interface for dealing with network traffic. You'll find, though, that even these are very simple.

For an IM application, there are two classes we're interested in. System.Net.Sockets.TcpClient and System.Net.Sockets.TcpListener provide methods for you to send and receive data, respectively, using the TCP protocol. All you need to know is the IP address of the person you want to communicate with, and you're set to go.

But wait a moment. An application cannot do two things at once. That is, your application cannot both send messages and receive them at the same time, which is a key feature of instant messaging. Somehow, you have to devise a way to accomplish two things at once—we'll discuss this in the next section.

  • + Share This
  • 🔖 Save To Your Account