Home

Requirements:
The project is implemented using Windows Socket 2.0 as a console application. Follow the following steps to create the development environment

Start Microsoft Visual C++.
Select the New menu item from File menu.
You will be shown a property sheet with four property pages with the titles "Files", "Project", "Workspace" and "Other Documents".
Click on the Workspace tab.
Select the appropriate Location and type in the name of the Workspace. In Visual C++ a Workspace is a collection of projects. Where project consists of various source file and defines what type of application is to be created.
One the workspace is created you will be able to see it in the left tab of the VC++ IDE.
Now create a project by selecting Project tab from the File -> New property sheet. Select the project type as "Win32 Console Application". Make sure that the "Add to Workspace" radio button is clicked otherwise the project will not be added to the existing workspace. Type in the name of the project. We need to create two projects one each for the server and client modules. Both projects MUST be "Win32 Console Application" and added to the same workspace.
Once you are done with the project creation make sure that you see the two projects, under the workspace that you have created, in the left side workspace window.
Applications that used Windows Socket 2.0 needs to link to WS2_32.dll. For this we have to make sure the projects link to WS2_32.lib file. To do so we have to add the lib file to the two projects. This is done by right-clicking on the project name and selecting the "Add Files to Project" menu item. The lib file WS2_32.lib you will find in the lib directory of Visual C++. If the WS2_32.lib file is not added to the project you will get linker error for all the Windows Socket 2.0 library functions, that you have used in the application.
Create the source files to the active project by clicking on File tab from the File -> New property sheet. Make sure that the "Add to Project" check box is checked, otherwise the file will not be added to the project.
The prototype of Windows Socket 2.0 library functions are in winsock2.h header file so make sure that you include the file in your source files by using the #include pre-processor directive.

 

The Problem:
The aim of this tutorial is to demonstrate how can we implement a simple chat application. The application is a console based application and is implemented using Windows Socket 2.0. Application consists of two binaries

Server
The server module of the application waits for the client to connect to it. Once a client connects to the server, it can query server for different type of information, like list of all clients connected, etc. Another responsibility of the server is to let clients exchange the messages. In this application no two clients can exchange the data directly. They have to send the data thru server.
Client
The client module is the one that the user interacts with. User used the client to connect to the server. Once he establishes a connection, he can communicate with other users, also connected to the server.

Following are other features of the application

The server is multi-threaded which enables him to allow multiple clients to connect to him simultaneously.
Client and server establishes a TCP connection which implies that there will be no messages lost during transfer and also the order of messages will be maintained.
Currently the server never terminates.

 

Server Source code
Client Source code

 

More description coming soon !!!