Network Programming in .NET: With C# and Visual Basic .NET

4.3: Web Servers

4.3 Web Servers

One may ask why you should develop a server in .NET when IIS is freely available. An in-house-developed server has some advantages, such as the following:

  • Web server can be installed as part of an application, without requiring the user to install IIS manually from the Windows installation CD.

  • IIS will not install on the Windows XP Home Edition, which constitutes a significant portion of Windows users.

4.3.1 Implementing a Web Server

Start a new Visual Studio .NET project as usual. Draw two textboxes, tbPath and tbPort, onto the form, followed by a button, btnStart, and a list box named lbConnections, which has its view set to list.

At the heart of an HTTP server is a TCP server, and you may notice an overlap of code between this example and the TCP server in the previous chapter. The server has to be multithreaded, so the first step is to declare an Array List of sockets:

C#

public class Form1 : System.Windows.Forms.Form{  private ArrayList alSockets;  ...

VB.NET

Public Class Form1 Inherits System.Windows.Forms.Form    Private alSockets As ArrayList  ...

Every HTTP server has an HTTP root, which is a path to a folder on your hard disk from which the server will retrieve Web pages. IIS has a default HTTP root of C:\inetpub\wwwroot; in this case, we shall use the path in which the application is saved.

To obtain the application path, we can use Application.Executable-Path,...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Operating System Software
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.