Skip to content

VBMAN HelloWorld Example

Overview

This is an example of creating a basic web server using the VBMAN library, demonstrating the simplest HTTP server setup and route configuration.

Project Structure

Download source [ Note:To bin regedits DLL file ]

Please go to the home page to download the VBMAN project, decompress it, and open it with all DEMO projects.

Helloworld/
  ├── Form1.frm       # Main form, contains server startup code
  ├── bHello.cls      # Hello business class, handles specific requests
  └── VBMAN_DEMO.vbp  # VB6 project file

Core Code Analysis

1. Main Form (Form1.frm)

vb
Dim HttpServer As New cHttpServer

Private Sub Form_Load()
    With HttpServer
        .Router.Reg "Demo", New bHello    'Register business class
        .Router.AutoRoute = True          'Enable auto routing
        .Start 800                        'Start server, listen on port 800
    End With
    Shell "explorer.exe http://127.0.0.1:800/demo/hello"  'Automatically open browser to visit example
End Sub

2. Hello Business Class (bHello.cls)

vb
Public Sub Hello(ctx As cHttpServerContext)
    Dim id As Long: id = ctx.Request.QueryString("id") 'Get URL parameter id
    ctx.Response.Text "hello vbman @ " & id           'Return response text
End Sub

Feature Description

  1. HTTP Server Configuration

    • Create HTTP server using VBMAN library's cHttpServer class
    • Server listens on port 800
    • Automatically opens browser to visit example page when program starts
  2. Routing System

    • Register bHello class as Demo business handler
    • Enable auto routing feature (AutoRoute = True)
    • Route rule: /demo/hello maps to bHello.Hello method
    • URL parameter example: /demo/hello?id=123
  3. Request Handling

    • Get URL parameters through ctx.Request.QueryString
    • Return text response using ctx.Response.Text

Technical Points

  1. VBMAN handles web requests in an object-oriented way
  2. Auto routing feature can automatically generate URL paths based on class and method names
  3. Context object (ctx) provides complete request/response handling capabilities

Running Effect

After startup, it will automatically open the browser to visit http://127.0.0.1:800/demo/hello, and the page will display "hello vbman @ " followed by the provided id value.

Extension Suggestions

  1. Add more business methods to handle different URL requests
  2. Return different types of responses, such as JSON, HTML, etc.
  3. Add more URL parameter handling logic

VB6 and LOGO copyright of Microsoft Corporation