Skip to content

A feature-rich and high-performance RPC networking socket. Designed with ease of use in mind

Notifications You must be signed in to change notification settings

ShimmyMySherbet/NewSocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NewSocket

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.

WIP Web Socket library

Features:

Message Multi-casting

Transmit multiple messages at a time over a single connection. Prevents a single large message from blocking other messages.

Message Formats

Works using custom message formats or 'protocals', allowing you to implement custom message formats. For an example, see Object Transfer

RPC:

  • 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.

Binding 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.

Assign Automatically

  • 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;

Assign Manually:

  • 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;    
}

Querying Remote RPC

  • 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.

Performance

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.

Get Involved

Submit feature requests/ideas

Ask a question

My Discord

About

A feature-rich and high-performance RPC networking socket. Designed with ease of use in mind

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages