Ejemplo n.º 1
0
        public async Task RetrunOneArgument3()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            var v      = await client.RetrunOneArgument3(new[]
            {
                new TestObject()
                {
                    X = 10, Y = 99, Z = 100
                },
                new TestObject()
                {
                    X = 5, Y = 39, Z = 200
                },
                new TestObject()
                {
                    X = 4, Y = 59, Z = 300
                },
            });

            v[0].X.Should().Be(10);
            v[0].Y.Should().Be(99);
            v[0].Z.Should().Be(100);

            v[1].X.Should().Be(5);
            v[1].Y.Should().Be(39);
            v[1].Z.Should().Be(200);

            v[2].X.Should().Be(4);
            v[2].Y.Should().Be(59);
            v[2].Z.Should().Be(300);
            await client.DisposeAsync();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            this._isJoin = false;
            var channel = new Channel("localhost:8700", ChannelCredentials.Insecure);

            this._hub = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(channel, this);
        }
Ejemplo n.º 3
0
        public ChatClient(RichTextBox textBox)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            this.client  = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(channel, this);
            this.textBox = textBox;
        }
Ejemplo n.º 4
0
    private void Awake()
    {
        _animator = GetComponent <Animator>();

        _channel    = new Channel("localhost:12345", ChannelCredentials.Insecure);
        _controller = StreamingHubClient.Connect <IUnityChanController, IUnityChanControllerReceiver>(this._channel, this);
    }
Ejemplo n.º 5
0
        public async Task ScopedCreateInstancePerStreamingHub()
        {
            var serviceLocator = ((ServiceLocatorTestServerFixture.DummyServiceLocator)options.ServiceLocator);

            Assert.Empty(serviceLocator.StackedScopes);

            var client = StreamingHubClient.Connect <IServiceLocatorTestScopedHub, IServiceLocatorTestScopedHubReceiver>(channel, null);
            await client.HelloAsync();

            Assert.Single(serviceLocator.StackedScopes);
            Assert.Empty(serviceLocator.PoppedScopes);

            await client.HelloAsync();

            await client.HelloAsync();

            await client.HelloAsync();

            await client.HelloAsync();

            Assert.Single(serviceLocator.StackedScopes);
            Assert.Empty(serviceLocator.PoppedScopes);

            await client.DisposeAsync();

            Assert.Empty(serviceLocator.StackedScopes);
            Assert.Single(serviceLocator.PoppedScopes);
        }
Ejemplo n.º 6
0
        public void Initialize(
            CommandLineOptions options,
            PrivateKey privateKey,
            Action <bool> callback)
        {
            PrivateKey = privateKey;

            _channel = new Channel(
                options.RpcServerHost,
                options.RpcServerPort,
                ChannelCredentials.Insecure,
                new[]
            {
                new ChannelOption("grpc.max_receive_message_length", -1)
            }
                );
            _lastTipChangedAt = DateTimeOffset.UtcNow;
            _hub     = StreamingHubClient.Connect <IActionEvaluationHub, IActionEvaluationHubReceiver>(_channel, this);
            _service = MagicOnionClient.Create <IBlockChainService>(_channel);

            _genesis = BlockManager.ImportBlock(options.GenesisBlockPath ?? BlockManager.GenesisBlockPath);
            var appProtocolVersion = options.AppProtocolVersion is null
                ? default
                : Libplanet.Net.AppProtocolVersion.FromToken(options.AppProtocolVersion);

            AppProtocolVersion = appProtocolVersion.Version;

            RegisterDisconnectEvent(_hub);
            StartCoroutine(CoTxProcessor());
            StartCoroutine(CoJoin(callback));
        }
Ejemplo n.º 7
0
        public async Task Main()
        {
            logger.LogInformation("Starting DFrame worker node");

            var channel = new Channel(options.WorkerConnectToHost, options.WorkerConnectToPort, ChannelCredentials.Insecure,
                                      new[] {
                // keep alive
                new ChannelOption("grpc.keepalive_time_ms", 2000),
                new ChannelOption("grpc.keepalive_timeout_ms", 3000),
                new ChannelOption("grpc.http2.min_time_between_pings_ms", 5000),
            });
            var nodeId     = Guid.NewGuid();
            var receiver   = new WorkerReceiver(channel, nodeId, provider, options);
            var callOption = new CallOptions(new Metadata {
                { "node-id", nodeId.ToString() }
            });
            // explict channel connect to resolve slow grpc connection on fatgate.
            await channel.ConnectAsync(DateTime.UtcNow.Add(options.Timeout));

            var client = StreamingHubClient.Connect <IMasterHub, IWorkerReceiver>(channel, receiver, option: callOption, serializerOptions: options.SerializerOptions);

            receiver.Client = client;

            logger.LogInformation($"Worker -> Master connect successfully, WorkerNodeId:{nodeId.ToString()}.");
            try
            {
                // wait for shutdown command from master.
                await Task.WhenAny(receiver.WaitShutdown.WithCancellation(Context.CancellationToken), client.WaitForDisconnect());
            }
            finally
            {
                await ShutdownAsync(client, channel, nodeId);
            }
        }
Ejemplo n.º 8
0
    public async Task Start(string user, string room)
    {
        Debug.Log("Start Create Channel");
        var channel = new Channel("localhost:12345", ChannelCredentials.Insecure);

        Debug.Log("Start Connect Channel");
        var client = StreamingHubClient.Connect <IChatHub, IMessageReceiver>(channel, this);

        // RegisterDisconnect(client);
        try
        {
            Debug.Log("Start Join");

            await client.JoinAsync(user, room);

            Debug.Log("Start Send");
            await client.SendMessageAsync("Who");

            await client.SendMessageAsync("Bar");

            await client.SendMessageAsync("Baz");

            await client.LeaveAsync();
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
        finally
        {
            await client.DisposeAsync();
        }
    }
Ejemplo n.º 9
0
 private void InitializeClient()
 {
     // Initialize the Hub
     this.channel         = new Channel("localhost:12345", ChannelCredentials.Insecure);
     this.streamingClient = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(this.channel, this);
     this.client          = MagicOnionClient.Create <IChatService>(this.channel);
 }
Ejemplo n.º 10
0
        public override async Task SetupAsync(WorkerContext context)
        {
            _channel = new Channel(_host, 12346, ChannelCredentials.Insecure);
            var receiver = new EchoReceiver(_channel);

            _client         = StreamingHubClient.Connect <IEchoHub, IEchoHubReceiver>(_channel, receiver);
            receiver.Client = _client;
        }
Ejemplo n.º 11
0
        public async Task RetrunMoreArgument()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            var v      = await client.RetrunMoreArgument(10, "foo", 30.4);

            v.Should().Be(30.4);
            await client.DisposeAsync();
        }
Ejemplo n.º 12
0
        public async Task RetrunOneArgument()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            var v      = await client.RetrunZeroArgument();

            v.Is(1000);
            await client.DisposeAsync();
        }
Ejemplo n.º 13
0
    async void Start()
    {
        this.channel = new Channel("localhost", 12345, ChannelCredentials.Insecure);
        this.client  = StreamingHubClient.Connect <IBugReproductionHub, IBugReproductionHubReceiver>(this.channel, this);

        await this.client.JoinAsync();

        this.Button.onClick.AddListener(CallAsync);
    }
Ejemplo n.º 14
0
        /// <summary>
        /// <see cref="UnarySequentialDispatcherRemoteNode{TInput}"/>
        /// </summary>
        /// <param name="persistentCache">Persistent cache to avoid dropped data on system crash</param>
        /// <param name="progress">Progress of the current bulk</param>
        /// <param name="host"><see cref="Host"/></param>
        /// <param name="cts"><see cref="CancellationTokenSource"/></param>
        /// <param name="circuitBreakerOptions"><see cref="CircuitBreakerOptions"/></param>
        /// <param name="clusterOptions"><see cref="ClusterOptions"/></param>
        /// <param name="logger"><see cref="ILogger"/></param>
        public UnarySequentialDispatcherRemoteNode(
            IAppCache persistentCache,
            IProgress <double> progress,
            Host host,
            CancellationTokenSource cts,
            CircuitBreakerOptions circuitBreakerOptions,
            ClusterOptions clusterOptions,
            ILogger logger) : base(
                Policy.Handle <Exception>()
                .AdvancedCircuitBreakerAsync(circuitBreakerOptions.CircuitBreakerFailureThreshold,
                                             circuitBreakerOptions.CircuitBreakerSamplingDuration,
                                             circuitBreakerOptions.CircuitBreakerMinimumThroughput,
                                             circuitBreakerOptions.CircuitBreakerDurationOfBreak,
                                             onBreak: (ex, timespan, context) =>
        {
            logger.LogError(
                $"Batch processor breaker: Breaking the circuit for {timespan.TotalMilliseconds}ms due to {ex.Message}.");
        },
                                             onReset: context =>
        {
            logger.LogInformation(
                "Batch processor breaker: Succeeded, closed the circuit.");
        },
                                             onHalfOpen: () =>
        {
            logger.LogWarning(
                "Batch processor breaker: Half-open, next call is a trial.");
        }), clusterOptions, progress, cts, logger)
        {
            _logger         = logger;
            _clusterOptions = clusterOptions;

            ISubject <PersistentItem <TInput> > dispatcherSubject = new Subject <PersistentItem <TInput> >();
            _synchronizedDispatcherSubject             = Subject.Synchronize(dispatcherSubject);
            _synchronizedDispatcherSubjectSubscription = _synchronizedDispatcherSubject
                                                         .ObserveOn(new EventLoopScheduler(ts => new Thread(ts)))
                                                         .Select(item =>
            {
                return(Observable.FromAsync(() => persistentCache.AddItemAsync(item.Entity,
                                                                               item.CancellationTokenSource.Token)));
            })
                                                         .Merge()
                                                         .Subscribe();

            var channel = new Channel(host.MachineName, host.Port,
                                      ChannelCredentials.Insecure);
            _remoteContract = MagicOnionClient.Create <IRemoteContract <TInput> >(channel);
            IRemoteNodeSubject nodeReceiver = new NodeReceiver(_logger);
            _remoteNodeHealthSubscription =
                nodeReceiver.RemoteNodeHealthSubject.Subscribe(remoteNodeHealth =>
            {
                NodeMetrics.RemoteNodeHealth = remoteNodeHealth;
            });
            _nodeHub = StreamingHubClient.Connect <INodeHub, INodeReceiver>(channel, (INodeReceiver)nodeReceiver);

            NodeMetrics = new NodeMetrics(Guid.NewGuid());
        }
Ejemplo n.º 15
0
    void Start()
    {
        this.channel       = new Channel("localhost:12345", ChannelCredentials.Insecure);
        this.sampleService = MagicOnionClient.Create <ISampleService>(channel);
        this.sampleHub     = StreamingHubClient.Connect <ISampleHub, ISampleHubReceiver>(this.channel, this);

        this.SampleServiceTest(1, 2);

        this.SampleHubTest();
    }
Ejemplo n.º 16
0
 private void InitializeClient()
 {
     // Initialize the Hub
     this.channel = new Channel("localhost", 12345, ChannelCredentials.Insecure);
     // for SSL/TLS connection
     //var serverCred = new SslCredentials(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "server.crt")));
     //this.channel = new Channel("test.example.com", 12345, serverCred);
     this.streamingClient = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(this.channel, this);
     this.RegisterDisconnectEvent(streamingClient);
     this.client = MagicOnionClient.Create <IChatService>(this.channel);
 }
Ejemplo n.º 17
0
        public async Task ZeroArgument()
        {
            client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            await client.ZeroArgument();

            await voidZeroTask.Task;
            //await zeroTask.Task;
            // ok, pass.

            await client.DisposeAsync();
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            //初始化
            var channel      = new Channel("localhost:12345", ChannelCredentials.Insecure);
            var receiverChat = new ReceiverChat();
            var chatHub      = StreamingHubClient.Connect <IChatHub, IChat>(channel, receiverChat);

            chatHub.JoinAsync("Console Player", "Console Room");

            Console.ReadLine();
        }
Ejemplo n.º 19
0
    async void Start()
    {
        var channel = new Channel(LoginContext.Host, LoginContext.Port, ChannelCredentials.Insecure);

        _client = StreamingHubClient.Connect <IChatRoomHub, IChatRoomHubReceiver>(channel, this);

        await JoinAsync();

        View.OnLogoutClickedAsObservable().Subscribe(_ => LogoutAsync()).AddTo(this);
        View.OnInputAsObservable().Subscribe(mes => SpeakAsync(mes)).AddTo(this);
    }
Ejemplo n.º 20
0
    // Start is called before the first frame update
    void Start()
    {
        this._isJoin = false;

        //Client側のHubの初期化
        this._channel = new Channel("localhost:12345", ChannelCredentials.Insecure);
        this._chutHub = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(this._channel, this);

        //メッセージ送信ボタンはデフォルト非表示
        this.SendMessageButton.gameObject.SetActive(false);
    }
Ejemplo n.º 21
0
    public async Task <GameObject> ConnectAsync(Channel grpcChannel, string roomName, string playerName)
    {
        client = StreamingHubClient.Connect <IGamingHub, IGamingHubReceiver>(grpcChannel, this);
        var roomPlayers = await client.JoinAsync(roomName, playerName, Vector3.zero, Quaternion.identity);

        foreach (var player in roomPlayers)
        {
            (this as IGamingHubReceiver).OnJoin(player);
        }

        return(players[playerName]);
    }
Ejemplo n.º 22
0
        // Start is called before the first frame update
        void Start()
        {
            this._isJoin = false;

            //初始化
            var channel = new Channel("localhost:12345", ChannelCredentials.Insecure);

            this._chatHub = StreamingHubClient.Connect <IChatHub, IChat>(channel, this);

            //默认隐藏发送消息按钮
            this.SendMessageButton.gameObject.SetActive(false);
        }
Ejemplo n.º 23
0
    void Init()
    {
        IdPlayer   = -1;
        isJoin     = false;
        isGameOver = false;
        panel.SetActive(true);
        var channel = new Channel(ipServer + ":12345", ChannelCredentials.Insecure);

        _gameHub = StreamingHubClient.Connect <IGameHub, IGameHubReceiver>(channel, this);
        JoinOrLeave();
        InitBoard();
    }
Ejemplo n.º 24
0
        public async Task MoreArgument()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            await client.MoreArgument(100, "foo", 10.3);

            //var x = await moreTask.Task;
            var y = await voidmoreTask.Task;

            //x.Should().Be((100, "foo", 10.3));
            y.Should().Be((100, "foo", 10.3));
            await client.DisposeAsync();
        }
Ejemplo n.º 25
0
        public async Task OneArgument()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            await client.OneArgument(100);

            //var x = await oneTask.Task;
            var y = await voidoneTask.Task;

            //x.Should().Be(100);
            y.Should().Be(100);
            await client.DisposeAsync();
        }
        private async Task Start()
        {
            _channel = new Channel(host, port, ChannelCredentials.Insecure);

            var client = MagicOnionClient.Create <ISampleService>(_channel);
            var greet  = await client.GreetAsync(user);

            Debug.Log(greet);

            _receiver = new SampleHubReceiver();
            _hub      = StreamingHubClient.Connect <ISampleHub, ISampleHubReceiver>(_channel, _receiver);
            await _hub.JoinAsync(user, room);
        }
Ejemplo n.º 27
0
        public async Task RetrunOneArgument2()
        {
            var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this);
            var v      = await client.RetrunOneArgument2(new TestObject()
            {
                X = 10, Y = 99, Z = 100
            });

            v.X.Should().Be(10);
            v.Y.Should().Be(99);
            v.Z.Should().Be(100);
            await client.DisposeAsync();
        }
Ejemplo n.º 28
0
        private void ReconnectServer()
        {
            this.streamingClient = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(this.channel, this);
            this.RegisterDisconnectEvent(streamingClient);
            Debug.Log("Reconnected server.");

            this.JoinOrLeaveButton.interactable = true;
            this.SendMessageButton.interactable = false;
            this.SendReportButton.interactable  = true;
            this.DisconnectButon.interactable   = true;

            this.isSelfDisConnected = false;
        }
Ejemplo n.º 29
0
    async void Start()
    {
        this.channel             = new Channel("localhost:12345", ChannelCredentials.Insecure);
        this.sampleHub           = StreamingHubClient.Connect <ISampleHub, ISampleHubReceiver>(channel, this);
        Application.wantsToQuit += Application_wantsToQuit;

        msg.text = "";
        await this.sampleHub.JoinAsync(myName);

        await this.sampleHub.SendMessageAsync($"Hello outside world.");

        await this.sampleHub.MovePosition(sharedTarget.transform.position, sharedTarget.transform.rotation);
    }
        public async Task <GameObject> ConnectAsync(Channel grpcChannel, string roomName, string playerName)
        {
            var client = StreamingHubClient.Connect <IGamingHub, IGamingHubReceiver>(grpcChannel, this);

            var roomPlayers = await client.JoinAsync(roomName, playerName);

            // なぜサーバーからではなくクライアントから自前でみんなに通知しているのか分からないのでコメント化
            //foreach (var player in roomPlayers) {
            //	(this as IGamingHubReceiver).OnJoin(player);
            //}

            return(players[playerName]);            // 名前だけでマッチとか脆弱の極みですが、まぁサンプルなので。
        }