Skip to content

cHttpServer Methods Reference

🚀 Server Control Methods

Start

Starts HTTP server.

vb
Public Function Start(Optional Port As Long = 80, Optional WebRoot As String = "", Optional IP As String = "0.0.0.0") As Boolean

Parameters:

  • Port - Listen port (default 80)
  • WebRoot - Static file root directory
  • IP - Listen IP address (default 0.0.0.0 means all interfaces)

Returns: Returns True on success, False on failure

Example:

vb
' Basic start
If Server.Start(8080) Then
    Debug.Print "Server started successfully"
End If

' With static file directory
If Server.Start(8080, "C:\WebRoot") Then
    Debug.Print "Server started successfully"
End If

' Specify IP
If Server.Start(8080, "C:\WebRoot", "127.0.0.1") Then
    Debug.Print "Local server started successfully"
End If

StopMe

Stops HTTP server.

vb
Public Function StopMe() As Boolean

Description: Closes all connections, releases resources.

Example:

vb
Private Sub Form_Unload(Cancel As Integer)
    Server.StopMe
    Set Server = Nothing
End Sub

Reg

Registers a controller.

vb
Public Function Reg(ControllerName As String, Controller As Object) As Boolean

Parameters:

  • ControllerName - Controller name
  • Controller - Controller object instance

Example:

vb
' Register controllers
Call Server.Router.Reg("User", New cUserController)
Call Server.Router.Reg("Api", New cApiController)

Add

Adds route rule.

vb
Public Function Add(RouteName As String, Handler As String, Optional MethodLimit As EnumRouteMethod = Any_) As Boolean

Parameters:

  • RouteName - Route path (e.g., "/user")
  • Handler - Handler (format: "ControllerName@MethodName")
  • MethodLimit - HTTP method limit:
    • Any_ - Any method (default)
    • OnlyGet - GET only
    • OnlyPost - POST only
    • OnlyPut - PUT only
    • OnlyDelete - DELETE only

Example:

vb
' Basic routes
Call Server.Router.Add("/", "Home@Index")
Call Server.Router.Add("/user", "User@List", OnlyGet)
Call Server.Router.Add("/user/create", "User@Create", OnlyPost)
Call Server.Router.Add("/user/update", "User@Update", OnlyPut)
Call Server.Router.Add("/user/delete", "User@Delete", OnlyDelete)

📡 Events

OnAccept

Triggers when new connection is accepted.

vb
Public Event OnAccept(ClientInfo As cHttpServerClientInfo, Disconnect As Boolean)

Parameters:

  • ClientInfo - Client info object
  • Disconnect - Set to True to reject connection

Example:

vb
Private Sub Server_OnAccept(ClientInfo As cHttpServerClientInfo, Disconnect As Boolean)
    Debug.Print "New connection: " & ClientInfo.IP & ":" & ClientInfo.Port
    
    ' IP blacklist check
    If ClientInfo.IP = "192.168.1.100" Then
        Disconnect = True  ' Reject connection
    End If
End Sub

OnLogs

Log event.

vb
Public Event OnLogs(ByVal Level As String, ByVal Content As String)

Example:

vb
Private Sub Server_OnLogs(ByVal Level As String, ByVal Content As String)
    Debug.Print "[" & Level & "] " & Content
End Sub

🔧 Controller Method Writing Specification

Controller methods receive one context parameter containing request and response objects:

vb
Public Sub ActionName(ctx As cHttpServerContext)
    ' ctx.Request - Request object
    ' ctx.Response - Response object
    ' ctx.Session - Session object
    ' ctx.Cookies - Cookies object
    ' ctx.Db - Database object (if configured)
End Sub

Example Controller:

vb
' cUserController.cls
Option Explicit

' GET /user
Public Sub List(ctx As cHttpServerContext)
    Dim users As New Scripting.Dictionary
    users("items") = Array("John", "Jane", "Bob")
    users("total") = 3
    ctx.Response.Json users, 0, "Success"
End Sub

' POST /user/create
Public Sub Create(ctx As cHttpServerContext)
    ' Get POST data
    Dim username As String
    username = ctx.Request.Form("username")
    
    ' Get JSON data
    ' username = ctx.Request.Json.GetItem("username")
    
    ctx.Response.Json Nothing, 0, "Created successfully"
End Sub

' GET /user?id=1
Public Sub Detail(ctx As cHttpServerContext)
    Dim id As String
    id = ctx.Request.QueryString("id")
    
    Dim user As New Scripting.Dictionary
    user("id") = id
    user("name") = "John"
    
    ctx.Response.Json user
End Sub

📦 Context Object Properties

cHttpServerContext

PropertyTypeDescription
RequestcHttpServerRequestRequest object
ResponsecHttpServerResponseResponse object
SessioncHttpServerSessionSession object
CookiescHttpServerCookiesCookies object
DbcDataBaseDatabase object
ServercHttpServerSvrServer config
ClientInfocHttpServerClientInfoClient info

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation