NOTICE: The cloud-point-rpc library has been tested only on Linux on git tag v0.1.2. Other platforms are not supported by this version.
30 lines
943 B
C#
30 lines
943 B
C#
using System;
|
|
using UnityEngine;
|
|
using CloudPointRpc;
|
|
|
|
public class MinimalRpcServer : MonoBehaviour
|
|
{
|
|
[SerializeField] private string serverIp = "127.0.0.1";
|
|
[SerializeField] private int serverPort = 9095;
|
|
|
|
private static CrpcTestApi.RpcStringCallback _pingCallback;
|
|
|
|
[AOT.MonoPInvokeCallback(typeof(CrpcTestApi.RpcStringCallback))]
|
|
private static IntPtr OnPing(IntPtr rpcStringPtr)
|
|
{
|
|
var req = new RpcString(rpcStringPtr);
|
|
Debug.Log($"[MinimalRpcServer] ping received: {req.Data}");
|
|
return new RpcString("\"pong\"").Handle;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
_pingCallback = OnPing;
|
|
CrpcTestExtensions.CrpcInitWithAddress(serverIp, serverPort);
|
|
CrpcTestExtensions.CrpcAddMethod(_pingCallback, "ping");
|
|
Debug.Log($"[MinimalRpcServer] TCP server started on {serverIp}:{serverPort}, ping registered");
|
|
}
|
|
|
|
void OnDestroy() => CrpcServerApi.crpc_deinit();
|
|
}
|