Xb2.NET Samples

The following samples can only be run from a web browser connected to the sample Xb2.NET HTTP server (WEBSERVE.EXE). If you are simply browsing this file from the Windows explorer then do this:

  1. Open a command prompt.
  2. Change directory to where you installed Xb2.NET.
  3. Type PBUILD to build all samples.
  4. Type WEBSERVE to run sample HTTP server.
  5. Open a web browser and navigate to: http://localhost
  6. The Xb2.NET "Start Here" page should appear in your browser.

Launch sample applications
Source CodeSampleDescription
GetWeb.prg GetWeb.exe Execute an HTTP GET command, for example retrieve a file hosted on HTTP server.
PostWeb.prg PostWeb.exe Shows how to POST a request to an HTTP server.
Attach.prg Attach.exe Create a DIME payload containing several large files and upload to HTTP server.
TServer.prg TServer.exe Simple Telnet server application.
TClient.prg TClient.exe Simple Telnet client application.
FTPTest.prg FTPTest.exe FTP client test application.
SOAPExec.prg SOAPExec.exe SOAP client samples showing how to execute functions on remote servers.
Web Basics
! Some of the functions below are provided for educational purposes only. For security reasons, they should not be included on a production or public server.
Source CodeSampleDescription
WebFunc.prg Run a DOS Command Get a directory listing of all files in HTTP server's executable folder.
Execute a Codeblock Execute an Xbase++ codeblock on server and return result to client.
Generate Error Shows what happens when a runtime error occurs on the HTTP server.

! If you use Internet Explorer or Edge, you will need to turn off the "Show friendly HTTP error messages" in the browser's advanced settings so that the actual Xbase++ error log is displayed.

Calculate CRC32 Calculate CRC32 (Cyclic Redundancy Check) for a file.
Send Chunks Shows how to send dynamic content incrementally.
Direct Function Call Call an Xbase++ function and pass parameters to it directly.

! For security reasons, only character, numeric and logical values are supported.

WWW Basic Authentication Brings up a login screen to authenticate a client using "WWW-Authenticate" basic authentication.
Enter user name: "bugsbunny", password: "whatsup" (all lowercase).

Using basic authentication you only need to log in once for the duration of the session. After entering your credentials, the browser automatically sends them on subsequent requests to the same domain. If you click the link again, the authentication dialog is no longer displayed.

Upload File Upload one or more files from client computer to server.
Session Management Samples showing how to generate dynamic HTML, database access and use of HTTP session management.
ProgressBar.prg Progress Bar Display a progress bar that is updated by the server in real time (requires JavaScript support).
TimeClock.prg TimeClock application Web based TimeClock application.
HTTP Server Push Technologies
Source CodeSampleDescription
WebFunc.prg AJAX Test Ajax defines a web framework for dynamically pulling data from the server. Ajax makes it possible to update small sections of an HTML document with new data without requiring a complete page refresh.
Comet Test Simple example of how to implement server push also known as "Comet" and "reverse Ajax". The Comet pattern is based on creating and maintaining long-lived HTTP connections that enable the server to push events or data to the client without waiting for the client to request it.

! Some browsers will not display the pushed content until a certain amount of data is received. Because this sample is pushing a very small amount of data it may take 30 seconds for the pushed content to appear in the browser.

WebSocket - enables persistent TCP connection between server and client
!The WebSocket class requires the OpenSSL library and an Xb2.NET SSL license. Download OpenSSL from here (unzip file in same directory where you installed Xb2.NET).
Source CodeSampleDescription
WebServe.prg WebSocket Echo Server Establish a long-lived WebSocket connection between a client and Xb2.NET HTTP server. Because the connection is established using regular HTTP (or HTTPS for security), it is able to traverse proxies and firewalls that would ordinarily block regular socket connections. Once the connection is opened, data can be streamed in either direction between client and server.
WSChat.prg WebSocket Chat Room A simple chat room server using a WebSocket connection between web client and Xb2.NET HTTP server.
WSClient.prg WSClient.exe xbWebSocket client-side test program.
Compiled Xbase++ .PRG script Frequently Asked Questions
Source CodeSampleDescription
Hello.prg Hello Dynamic HTML page generated by Xbase++ PRG script compiled on-the-fly. If the PRG is modified, the Xb2.NET engine automatically recompiles it and the new code is loaded into memory (no need to restart the server).

! PRG scripts are compiled by the Xbase++ compiler (XPP.EXE). In order to auto-compile script on a Xb2.NET HTTP server, the full compiler must be installed on the server. Furthermore, if the HTTP server is installed as a service, the Xbase++ environment must be available to the service account (PATH, INCLUDE, LIB, XPPRESOURCE). A simple alternative is to copy the contents from the .\bin, .\lib and .\include Xbase++ installation folders into the Xb2.NET HTTP server application folder (where the .exe is installed).

Hello2.prg Hello2 Dynamic HTML page generated by Xbase++ PRG script compiled on-the-fly. If the PRG is modified, the Xb2.NET engine automatically recompiles it and the new code is loaded into memory (no need to restart the server).

! PRG scripts are compiled by the Xbase++ compiler (XPP.EXE). In order to auto-compile script on a Xb2.NET HTTP server, the full compiler must be installed on the server. Furthermore, if the HTTP server is installed as a service, the Xbase++ environment must be available to the service account (PATH, INCLUDE, LIB, XPPRESOURCE). A simple alternative is to copy the contents from the .\bin, .\lib and .\include Xbase++ installation folders into the Xb2.NET HTTP server application folder (where the .exe is installed).

Colors.prg HTML Colors
AjaxListBox.prg Populate List Box using AJAX Shows how AJAX can be used to fill a List Box on a web page with data fetched from the server.
AjaxCalc.prg AJAX Calculator Use AJAX to send a simple string of data to the server, the server calculates the result and sends back the answer in the HTTP response. JavaScript is used on the client-side to display the result without refreshing the entire page.
StatePersistence.prg Page Load Counter An example of how to maintain state persistence when the HTTP server is restarted or when a PRG script is modified and it's DLL is reloaded.
Checkout.prg Process payment using PayUnity service A fully functional webshop checkout using PayUnity service: https://payunity.docs.oppwa.com/
UsingMacro.prg Execute function in main .exe This sample shows one way of calling functions found in the main .EXE from a .PRG script.
Compile_err.prg Compile error in .prg script This sample shows how compile/link errors are displayed in browser when a PRG script contains errors.

! If you use Internet Explorer or Edge, you will need to turn off the "Show friendly HTTP error messages" in the browser's advanced settings so that the actual error message is displayed.