/// <summary> /// Initializes an <see cref="RpcClient"/> using the specified connection. /// </summary> /// <param name="connection"> /// The underlying connection used to exchange messages /// </param> /// <param name="rpcTarget"> /// The object where remote procedure calls from the server /// are executed on. Set this to null if you do not want to allow /// RPC calls from the server to the client. /// </param> public RpcClient(IConnection connection, object rpcTarget) { _connection = new RpcConnection(connection); _rpcTarget = rpcTarget; _requestReceivedSubscription = connection.RequestReceived .Where(r => r.Message is RpcCall) .Subscribe(r => RpcHelper.HandleMethodCall(_connection, r, _rpcTarget)); _disconnectedSubscription = connection.Disconnected.Subscribe(OnDisconnected); (rpcTarget as IRpcTarget)?.OnConnected(_connection); }
private async void OnConnectionReceived(IConnection connection) { if (connection != null) { await _sema.WaitAsync(); var rpcConnection = new RpcConnection(connection); var connectionInfo = new RpcConnectionInfo(rpcConnection, connection.RequestReceived .Where(r => r.Message is RpcCall) .Subscribe(r => RpcHelper.HandleMethodCall(rpcConnection, r, _rpcTarget)), connection.Disconnected .Subscribe(args => OnClientDisconnected(rpcConnection, args))); _connections.Add(connection.Id, connectionInfo); (_rpcTarget as IRpcTarget)?.OnConnected(rpcConnection); _sema.Release(); } }