Skip to content

AWaterColorPen/HoleOverHttp

Repository files navigation

HoleOverHttp

Build Status NuGet version

Library to help providing server api and connection to client. Implementation in C#, targeting .NET Standard 2.1+.

The library can help server acoss network security groups and firewall to provider api and connection to multi clients.

Usage

  • Install
Install-Package HoleOverHttp
  • Provider Connection
IAuthorizationProvider authorizationProvider = new Mock<IAuthorizationProvider>().Object;
var providerConnection = new WebSocketProviderConnection(host: "localhost:23333", namespace: "namespace", tokenProvider: authorizationProvider);

// set secure
providerConnection.Secure = false;
  • Service Object as a class
public class ServiceObject
{
    public int MethodName(int param)
    {
        return param * param;
    }
}
  • Server Provider
// register service and connection
var serverProvider = new ReflectCallProvider();
serverProvider.RegisterConnection(providerConnection);
serverProvider.RegisterService(new ServiceObject());

// run serve async
var tokenSource = new CancellationTokenSource();
await serverProvider.ServeAsync(tokenSource.Token);
  • Client Call Registry
// create a call registry instance 
var callConnectionPool = new ReusableCallConnectionPool();
// have to implementation your own CallRegistry instance
var webListenerCallRegistry = new WebListenerCallRegistry(callConnectionPool: callConnectionPool, prefixes: new[] { "http://localhost:23333/ws/" }));

// enable remote register
var tokenSource = new CancellationTokenSource();
webListenerCallRegistry.RegisterRemoteSocket(tokenSource.Token);
  • Client Call
var result = callConnectionPool.CallAsync(namespace: "namespace", method: "MethodName", param: Encoding.UTF8.GetBytes("{param:0}")).Result;

Releases

No releases published

Packages

No packages published

Languages