SimpleDUTRemote
A simple automation solution
Public Member Functions | Properties | Events | List of all members
SimpleJsonRpc.SimpleRpcServer Class Reference

Main class for the RPC system. More...

Public Member Functions

async Task Start (int serverPort=8000, IPAddress ip=null, int? broadcastPort=null)
 Start the internal json rpc server, on a specific port. Optionally start broadcast server. More...
 
void Stop ()
 Stops the internal json rpc server. More...
 
void Register (object rpcObject)
 Register an object that has SimpleRpcMethod annotations. More...
 
string HandleJsonString (string jsonString)
 Manually process an inbound json rpc request. More...
 
void HandleClient (TcpClient client)
 

Properties

static AsyncLocal< IPEndPoint > currentClient [get]
 

Events

Action Starting = new AsyncLocal<IPEndPoint>()
 
Action Stopping
 

Detailed Description

Main class for the RPC system.

The RpcServer class handles processing RPC requests. It can be used either as a stand-alone server, or with an existing solution (and just provide parsing, method lookup and execution, and result serialization).

The general flow for using this class is:

This class handles parsing requests, looking up and running methods, and serializing results. If you're looking for the functions that you can call via RPC, please see you should review the documentation for the registered object.

Member Function Documentation

◆ HandleJsonString()

string SimpleJsonRpc.SimpleRpcServer.HandleJsonString ( string  jsonString)
inline

Manually process an inbound json rpc request.

If you aren't using the built in server, you can use this method to manually process a json-rpc string, and have it return the result string.

Parameters
jsonStringJson rpc request (as a string)
Returns
Json rpc result, as a string.

◆ Register()

void SimpleJsonRpc.SimpleRpcServer.Register ( object  rpcObject)
inline

Register an object that has SimpleRpcMethod annotations.

Register functions (with the SimpleRpcMethod annotation) with the rpc system. Once registered, inbound rpc requests can call methods that were annotated.

This stores a copy of the object - any inbound rpc call that matches a registered method name will be called against the provided object.

If you register several objects that have an annotated function with the same name, the last one registered will be called.

Parameters
rpcObjectObject with SimpleRpcMethod annotations.

◆ Start()

async Task SimpleJsonRpc.SimpleRpcServer.Start ( int  serverPort = 8000,
IPAddress  ip = null,
int?  broadcastPort = null 
)
inline

Start the internal json rpc server, on a specific port. Optionally start broadcast server.

This starts a TcpListener on the given port, listens for inbound json rpc requests, reads to the first new line character, parses the request, calls the appropriate registered method based on the method name, and sends back the json rpc response.

If broadcastPort is specified, it will create a UDP listener on the given port, and wait for broadcast packets with the message "SimpleJsonRpc Ping". When one is received, it will respond with the current json rpc server port. This is primarily used in lab test environments only.

If you plan on using this behind another server, you may be better served by skipping this method and using HandleJsonString() directly.

Parameters
serverPortPort to listen for rpc requests
ipIP to bind to - use null for all interfaces.
broadcastPortPort to use to listen for broadcast pings. Use null to disable broadcast support.
Returns
Task for the running server.

◆ Stop()

void SimpleJsonRpc.SimpleRpcServer.Stop ( )
inline

Stops the internal json rpc server.


The documentation for this class was generated from the following file: