I don't know what to call this socket yet, but I don't want to keep it as 'NewSocket'
This page needs to be filled out. In the mean time, see Client and Server examples.
Transmit multiple messages at a time over a single connection. Prevents a single large message from blocking other messages.
Works using custom message formats or 'protocals', allowing you to implement custom message formats. For an example, see Object Transfer
- Invoking/Querying a remote RPC is asyncronous, however the RPC handler doesn't have to be async.
- Handlers can be instance based or static.
- All objects are automatically serialized/deserialized. Allowing for class and struct return types and parameters.
- RPC handlers can be manually assigned, or automatically assigned using attributes.
- Bind remote RPC to delegate.
- Creates a new instance of the specified delegate type and binds it to the remote RPC.
- All parameters passed to it are used when invoking the remote RPC handler.
- The delegate type can run the query async (Task<object.>) or blocking (object.). It is recomended to run queries async.
- The remote RPC name is attached to the delegate type using the RPC attribute.
- The remote RPC name can also be supplied using
.GetRPC<DelegateType>("RemoteMethodName")
[RPC("Login")]
public delegate Task<bool> LoginRPC(string username, string password);
var Login = Client.RPC.GetRPC<LoginRPC>();
// login
var loggedIn = await Login("Username", "Password");
if (loggedIn)
{
Console.WriteLine("Logged in!");
}
This allows remote RPCs to be stored as a variable and invoked like a normal method.
See below for remote method.
- If the RPC name is omitted in the RPC attribute, the method name will be selected instead.
Client.RPC.RegisterFrom(this);
[RPC("Login")]
public async Task<bool> Login(string username, string password)
{
var result = await Auth.LoginAsync(username, password);
IsLoggedIn = result.LoggedIn;
return result.LoggedIn;
}
[RPC]
public string GetName()
{
return ClientUsername;
}
[RPC]
public static DateTime GetTime() => DateTime.Now;
- You can pass any delegate type to
Subscribe()
Client.RPC.Subscribe("GetLoginState", GetLoginState);
public async Task<bool> Login(string username, string password)
{
var result = await Auth.LoginAsync(username, password);
IsLoggedIn = result.LoggedIn;
return result.LoggedIn;
}
- An alternate from binding an RPC to a delegate
var result = await Client.RPC.QueryAsync<bool>("Login", "Username", "Password");
For more examples, see Client.cs and Server.cs examples.
Querying GetTime
from the auto assign example on average took 0.18ms.
This is the time from querying and reciving the response, including the minimal network time in testing.
My Discord