SimpleDUTRemote
A simple automation solution
|
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 |
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.
|
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.
jsonString | Json rpc request (as a string) |
|
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.
rpcObject | Object with SimpleRpcMethod annotations. |
|
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.
serverPort | Port to listen for rpc requests |
ip | IP to bind to - use null for all interfaces. |
broadcastPort | Port to use to listen for broadcast pings. Use null to disable broadcast support. |
|
inline |
Stops the internal json rpc server.