Skip to content

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

License

Notifications You must be signed in to change notification settings

k0dep/Unity-Json-Rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages