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
| Feature | Description |
|---|---|
| HTTP Service | Supports GET/POST/PUT/DELETE/OPTIONS methods |
| Router System | Supports manual route registration and auto routing |
| Session Management | Supports memory, file system, database storage |
| Cookie Handling | Complete cookie parsing and setting |
| Static Files | Auto serve static files |
| SSE Support | Server-Sent Events real-time push |
| CORS Handling | Built-in CORS support |
| MVC Architecture | Supports controller-view-model development |
| Packet Coalescing | Auto 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 SubSession 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 SubCORS 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 SubFile Structure
| File | Description |
|---|---|
cHttpServer.cls | Main server class |
cHttpServerRouter.cls | Router |
cHttpServerRequest.cls | Request object |
cHttpServerResponse.cls | Response object |
cHttpServerSession.cls | Session management |
cHttpServerCookies.cls | Cookie management |
cHttpServerContext.cls | Context object |
cHttpServerClientInfo.cls | Client info |
cHttpServerRouteBefore.cls | Before route |
cHttpServerRouterAfter.cls | After route |
cHttpCrossDomain.cls | CORS handling |
References
cTlsReMaster.cls- TLS/Network communicationcJson.cls- JSON handlingcScriptEngine.cls- Script enginecDataBase.cls- Database (optional)cSSE.cls- SSE support
Last Updated: 2026-05-17