Tcp-based client?
knocte opened this issue · 2 comments
Hey, just stumbled upon your cute lib.
It seems plain sockets are supported (not only HTTP, but TCP) as there's a docs section about it: https://github.com/Astn/JSON-RPC.NET/wiki/Getting-Started-(Sockets)
However, that section on the documentation only explains the server side part.
How to connect via TCP simply from a client perspective? The client class (https://github.com/Astn/JSON-RPC.NET/blob/master/AustinHarris.JsonRpc.Client/client.cs) receives a URI, which means I need to specify a protocol-scheme (e.g. http:// ), which is not TCP-agnostic.
Oh, and I just realised you're using HttpWebRequest directly, so I guess this lib is not TCP compatible from the client side then?
Hey Knocte,
I use the TCP-based server side exclusively in all the projects I'm working on. You're right it's not the most common of ways to use this library, and so not the focus. The client side is actually very simple, you can use a regular socket connection. Let me know if you need any help in getting setup, I would have benefitted when I started using this library :).
The client-side serialization is the key part that's missing, but also can be done easily. I use a general class on the client side, see here:
public class JsonRequest
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "jsonrpc")]
public string jsonrpc = "2.0";
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "method")]
public string method = "";
[JsonProperty(NullValueHandling = NullValueHandling.Include, PropertyName = "params")]
public List<Object> parameters = new List<object>();
[JsonProperty(NullValueHandling = NullValueHandling.Include, PropertyName = "id")]
public int id = 1;
public JsonRequest(string method,params object[] parameters)
{
this.method = method;
this.parameters = parameters.ToList();
}
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
Hi Knocte,
It is not currently one of our objectives to provide transport protocol implementations server side or client side. We do provide libraries that can be used if you provide the protocol wiring. Also the client classes in this repo are generally just used for running our tests.
However because we follow the Json-rpc 2.0 spec, any json-rpc 2.0 client library should work with this server, assuming you hook up the transport protocol plumbing.