Wednesday, January 25, 2017

A HTTP server embedded inside Unity3D.

Just 514 lines of code. Uses sockets only, no other dependencies.

https://github.com/simonwittber/uniwebserver

Example Component:

[RequireComponent(typeof(EmbeddedWebServerComponent))]
public class FileUpload : MonoBehaviour, IWebResource
{
    public string path = "/upload";
    public TextAsset html;
    EmbeddedWebServerComponent server;

    void Start ()
    {
        server = GetComponent<EmbeddedWebServerComponent>();
        server.AddResource(path, this);
    }
 
    public void HandleRequest (Request request, Response response)
    {
        response.statusCode = 200;
        response.message = "OK.";
        response.Write(html.text);
    }
}    

No comments:

Popular Posts