Skip to content

afjk/TinyHttpServerForUnity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyHttpServer for Unity

TinyHttpServer is a simple HTTP server implemented in C#. It uses the HttpListener class to listen for HTTP requests and handle them asynchronously.

Features

  • GET and POST Request Handling: The server can handle GET and POST requests.

  • Customizable Port and Document Root: You can set the port and document root for the server.

  • Delegates for Data Processing: You can assign delegates to process the received text and binary data from POST requests.

Installation

Install via OpenUPM

To install the TinyHttpServer package using OpenUPM, run the following command in your project’s root folder:

openupm add com.afjk.tinyhttpserver

Install via Unity Package Manager (UPM)

To install the TinyHttpServer package using Unity Package Manager, follow these steps:

Using Scoped Registries

  1. Open your project’s manifest.json file.
  2. Add the following scoped registry configuration:
"scopedRegistries": [
    {
      "name": "afjk's UPM registory",
      "url": "https://upm.afjk.jp",
      "scopes": [
        "com.afjk"
      ]
    }
  ]
  1. Save the file.
  2. In UnityEditor, go to Window > Package Manager.
  3. Select the My Registries section in the left panel.
  4. Search for TinyHttpServerForUnity and install it.

Using Project Settings

Alternatively, you can configure the registry via Project Settings:

  1. In UnityEditor, go to Edit > Project Settings > Package Manager.
  2. Under Scoped Registries, add the following details:

You can now find and install TinyHttpServerForUnity in the Package Manager.

Install from Git URL

Alternatively, to install the TinyHttpServer package using Unity Package Manager, follow these steps:

  1. Open the Unity Editor and go to Window -> Package Manager.
  2. Click the + button in the top-left corner.
  3. Select Add package from git URL....
  4. Enter the following URL to install the latest version:
https://github.com/afjk/TinyHttpServerForUnity.git?path=/Packages/com.afjk.tinyhttpserver#v0.0.1

Importing and Running Samples

After installing the TinyHttpServer package, you can use the built-in Editor extension to launch a sample HTTP server:

  1. Open the Unity Editor and go to the menu bar.
  2. Navigate to Tools -> Tiny HTTP Server to open the server control panel.
  3. In the Port Number field, specify the desired port (e.g., 8080).
  4. Click the Start Server button to launch the HTTP server.

Verifying the Server

Once the server is started, the control panel will display the Server URL. You can:

  • Copy URL: Copy the server URL to your clipboard.
  • Open in Browser: Launch your default web browser to view the server’s content.
  • Open Document Folder: Open the folder that serves as the document root for the server.

The attached screenshots below show the sample UI for starting and managing the server:

image image

Usage

To use the server, you need to create an instance of the TinyHttpServer class, define your routes and start the server. Here is a basic example:

var server = new TinyHttpServer();
server.Port = 8080;
server.DocumentRoot = Path.Combine(Application.dataPath, "..", "html");
server.AddGetRoute("/example", HandleExampleGet);
server.AddPostRoute("/example", HandleExamplePost);
server.StartServer();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages