GithubHelp home page GithubHelp logo

k0dep / unity-json-rpc Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 10 KB

:scroll:🖥️Json rpc v1.0 server implementation for Unity3d package

License: MIT License

C# 100.00%
json-rpc server unity3d unity upm-package originer

unity-json-rpc's Introduction

UnityJsonRpc

Json-Rpc server for unity as upm package.

Sample

  1. Create Server.cs mono behaviour file:
using System.Collections.Concurrent;
using UnityEngine;
using UnityJsonRpc;
using Random = UnityEngine.Random;

public class Server : MonoBehaviour
{
    public int ListenPort = 8080;

    private JsonRpcServer server;
    private ConcurrentQueue<JsonRpcRequest> requests;
    
    public void Awake()
    {
        server = new JsonRpcServer();
        requests = server.Start("http://localhost:" + ListenPort + "/");
    }

    void Update()
    {
        if (requests.IsEmpty)
        {
            return;
        }

        if (requests.TryDequeue(out var request))
        {
            if (Random.value > 0.5)
            {
                request.Error(-121276);
            }
            else
            {
                request.Respond("ok");
            }
        }
    }
    
    public void OnDestroy()
    { 
        server.Stop();
    }
}
  1. Add Server component to some GameObject at scene
  2. Play
  3. Request(by Postman or another app) http://localhost:8080/ with payload:
{
	"method": "method"
}
  1. Take response

Using

For start using this package add lines into ./Packages/manifest.json like next sample:

{
  "dependencies": {
    "unity-json-rpc": "https://github.com/k0dep/unity-json-rpc.git"
  }
}

Or use it as dependency from another packages and auto include by Originer package

unity-json-rpc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

qipa

unity-json-rpc's Issues

Create github releases

Hi @k0dep ,

Thanks for creating the awesome package. Would please create a github release vx.y.z? So the package can be included in upcoming openupm registry (sneak preview), which is a service that build package directly from git tags that conform semver.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.