Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C#

C# WebServer Using Sockets

Rate me:
Please Sign up or sign in to vote.
5.00/5 (27 votes)
23 Jan 2014CPOL7 min read 103.9K   9.9K   161  
How to make a simple web server which supports GZIP compression, applications, and sessions.
using System;

namespace BizApplication
{
    /// <summary>
    /// Base class to build server side applications.
    /// Contains methods for interact with the server and for share data.    
    /// </summary>
    public abstract class ApplicationInstanceBase
    {
        //#### Declaration        
        private Guid applicationId;
        protected ApplicationResponse response;
        protected ApplicationRequest request;

        //#### Constructor
        public ApplicationInstanceBase()
        {
            this.applicationId = Guid.NewGuid();
        }

        /// <summary>
        /// Entry point for all client requests.        
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public ApplicationResponse ProcessRequest(ApplicationRequest req)
        {
            ///
            /// Firstable we clean the application data for the new request            
            /// 
            
            this.request = req;            
            this.response = null;            
            LastRequest = DateTime.Now;
      
            NewRequest();
            
            
            return this.response;
        }
       
        protected abstract void NewRequest();
        
        /// <summary>
        /// Incomging shared response from an application 
        /// </summary>
        /// <param name="sender">the application that elaborate the response</param>
        /// <param name="response"></param>
        /// <param name="req">the initial request</param>
        public abstract void OnNewShareResponse(ApplicationInstanceBase sender, ApplicationResponse response, ApplicationRequest req);

        /// <summary>
        /// Called by the server when disposed
        /// </summary>
        public abstract void UnloadApplication();

        //#### Return the application setting
        public abstract ApplicationSettings Info { get; }

        //#### Unique identifier application Id
        public Guid ApplicationId{get { return applicationId; } }

        //#### Last datetime request 
        public DateTime LastRequest { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
Alberto Biafelli,
Software Developer

Comments and Discussions