Skip to content

cHttpServer Component Overview

Introduction

cHttpServer is an HTTP server component based on VB6 that provides complete Web server functionality, supporting routing, session, cookie, static file service, SSE (Server-Sent Events), CORS handling, and more.

Features

FeatureDescription
HTTP ServiceSupports GET/POST/PUT/DELETE/OPTIONS methods
Router SystemSupports manual route registration and auto routing
Session ManagementSupports memory, file system, database storage
Cookie HandlingComplete cookie parsing and setting
Static FilesAuto serve static files
SSE SupportServer-Sent Events real-time push
CORS HandlingBuilt-in CORS support
MVC ArchitectureSupports controller-view-model development
Packet CoalescingAuto handles TCP packet coalescing

Architecture Overview

┌─────────────────────────────────────────────────────────┐
│                     cHttpServer                         │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
│  │   Router   │  │   Session  │  │    SSE     │     │
│  │ (Router)   │  │ (Session)  │  │(Real-time) │     │
│  └─────────────┘  └─────────────┘  └─────────────┘     │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
│  │   Request   │  │  Response   │  │   Context   │     │
│  │(Request Obj)│  │(Response)  │  │ (Context)   │     │
│  └─────────────┘  └─────────────┘  └─────────────┘     │
└─────────────────────────────────────────────────────────┘

Quick Start

Minimal HTTP Server

vb
Private WithEvents Server As cHttpServer

Private Sub Form_Load()
    Set Server = New cHttpServer
    
    ' Register routes
    Call Server.Router.Reg("Home", New cHomeController)
    Call Server.Router.Add("/", "Home@Index")
    Call Server.Router.Add("/user", "Home@User", OnlyGet)
    Call Server.Router.Add("/api/data", "Home@Api", OnlyPost)
    
    ' Start server
    If Server.Start(8080, "C:\WebRoot") Then
        Debug.Print "Server started: http://localhost:8080"
    Else
        Debug.Print "Start failed: " & Server.LastError
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Server.StopMe
End Sub

' Controller example
Public Sub Index(ctx As cHttpServerContext)
    ctx.Response.Html "<h1>Hello World!</h1>"
End Sub

Public Sub Api(ctx As cHttpServerContext)
    Dim data As New Scripting.Dictionary
    data("message") = "Success"
    data("time") = Now
    ctx.Response.Json data, 0, "OK"
End Sub

Session Configuration

vb
Private Sub Form_Load()
    Set Server = New cHttpServer
    
    ' Configure Session storage type
    Server.SessionStorageType = SessionStorageFileSystem  ' File storage
    Server.SessionStoragePath = "C:\Sessions"             ' Storage path
    Server.SessionCookieName = "MY_SESSIONID"             ' Cookie name
    
    ' Or use database storage
    ' Server.SessionStorageType = SessionStorageDatabase
    ' Server.SessionStoragePath = "sessions_table"
    
    Call Server.Start(8080, "C:\WebRoot")
End Sub

CORS Configuration

vb
Private Sub Form_Load()
    Set Server = New cHttpServer
    
    ' Enable CORS
    Server.CrossDomain.Enable = True
    Server.CrossDomain.AllowOrigin = "*"
    Server.CrossDomain.AllowMethods = "GET, POST, PUT, DELETE"
    Server.CrossDomain.AllowHeaders = "Content-Type, Authorization"
    Server.CrossDomain.AllowCredentials = True
    
    Call Server.Start(8080)
End Sub

File Structure

FileDescription
cHttpServer.clsMain server class
cHttpServerRouter.clsRouter
cHttpServerRequest.clsRequest object
cHttpServerResponse.clsResponse object
cHttpServerSession.clsSession management
cHttpServerCookies.clsCookie management
cHttpServerContext.clsContext object
cHttpServerClientInfo.clsClient info
cHttpServerRouteBefore.clsBefore route
cHttpServerRouterAfter.clsAfter route
cHttpCrossDomain.clsCORS handling

References

  • cTlsReMaster.cls - TLS/Network communication
  • cJson.cls - JSON handling
  • cScriptEngine.cls - Script engine
  • cDataBase.cls - Database (optional)
  • cSSE.cls - SSE support

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation