In part 1 of this article, you learned to create a mult-user chat application using network programming in .NET. In this article, you'll build on that application to add sophisticated features such as file downloads.

by Wei-Meng Lee

May 26, 2005

Page 1 of 5

n part 1of this article, you saw how to build your own instant messenger application that allows many users to chat simultaneously. While the application is interesting, it is not very flexible as you cannot choose the user(s) you want to chat with; all messages are broadcasted to everyone in the chat.

Building on the earlier article, I'll show you how to enhance the application to allow private chats between selected users. You will also build FTP support into the application so that you can transfer files between users.

Defining Your Own Protocol
In order to enhance the chat application, you have to define your own protocol for the various functions. For example, when you want to chat with someone, you need to indicate the user name to the server so that only messages destined for this user are sent to him. Similarly, when you need to perform a file transfer, there must be several handshaking processes to ensure that the recipient explicitly accepts the file transfer before it is sent.

This section describes the communication between the users and the server.

Logging in
User1 signs in to the server:

User1 sends [Join][User1] to the server indicating its presence

Server broadcast [Join][User1] to all the users currently connected

Requesting users' names
When User1 logs in to the server, he needs to know who is currently online:

User1 sends [Usrs] to the server, asking for a list of users currently online

Server sends back to User1 [Usrs][User1,User2,UserN,] containing a list of all user names