/// <summary> /// 接続開始 /// </summary> /// <param name="receiver"></param> /// <param name="ipAddr"></param> /// <param name="port"></param> /// <returns></returns> public async UniTask ConnectStartAsync() { while (!cancellationTokenSource.IsCancellationRequested) { try { // 本当にサーバーに接続できるか確認 await channel.ConnectAsync(DateTime.UtcNow.AddSeconds(5)); Debug.Log("connecting to the server ... "); ServerImpl = await StreamingHubClient.ConnectAsync <TServer, TClient>(channel, ClientImpl, cancellationToken : cancellationTokenSource.Token); executeDisconnectEventWaiterAsync(ServerImpl).Forget(); Debug.Log("established connect"); break; } catch (TaskCanceledException) { } catch (OperationCanceledException e) { Debug.LogWarning(e); throw new OperationCanceledException(); } catch (Exception e) { Debug.LogError(e); } Debug.Log("Retry after 2 seconds"); await UniTask.Delay(2 * 1000, cancellationToken : cancellationTokenSource.Token); } }
static async Task RunAsync(string endpoint, int port, string prefix, ChannelOption[] options) { var channel = new Channel(endpoint, port, ChannelCredentials.Insecure, options); var client = MagicOnionClient.Create <IEchoService>(new DefaultCallInvoker(channel)); var reply = await client.EchoAsync("hogemoge"); Console.WriteLine("Echo: " + reply); // duplex var receiver = new MyHubReceiver(); var hubClient = await StreamingHubClient.ConnectAsync <IMyHub, IMyHubReceiver>(new DefaultCallInvoker(channel), receiver); var roomPlayers = await hubClient.JoinAsync($"room {prefix}", "hoge"); foreach (var player in roomPlayers) { receiver.OnJoin(player); } var i = 0; while (i++ < 100) { await hubClient.SendAsync($"{prefix} {i}"); await Task.Delay(TimeSpan.FromSeconds(60)); } await hubClient.LeaveAsync(); await hubClient.DisposeAsync(); await channel.ShutdownAsync(); }
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(); }
private async Task InitializeClientAsync() { // Initialize the Hub // NOTE: If you want to use SSL/TLS connection, see InitialSettings.OnRuntimeInitialize method. this.channel = GrpcChannelx.ForAddress("http://localhost:5000"); while (!shutdownCancellation.IsCancellationRequested) { try { Debug.Log($"Connecting to the server..."); this.streamingClient = await StreamingHubClient.ConnectAsync <IChatHub, IChatHubReceiver>(this.channel, this, cancellationToken : shutdownCancellation.Token); this.RegisterDisconnectEvent(streamingClient); Debug.Log($"Connection is established."); break; } catch (Exception e) { Debug.LogError(e); } Debug.Log($"Failed to connect to the server. Retry after 5 seconds..."); await Task.Delay(5 * 1000); } this.client = MagicOnionClient.Create <IChatService>(this.channel); }
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); }
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)); }
private void Awake() { _animator = GetComponent <Animator>(); _channel = new Channel("localhost:12345", ChannelCredentials.Insecure); _controller = StreamingHubClient.Connect <IUnityChanController, IUnityChanControllerReceiver>(this._channel, this); }
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); } }
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); }
private async Task InitializeClientAsync() { // Initialize the Hub this.channel = new Channel("localhost", 5000, ChannelCredentials.Insecure); // for SSL/TLS connection //var cred = new SslCredentials(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "server.crt"))); //this.channel = new Channel("dummy.example.com", 5000, cred); // local tls //this.channel = new Channel("your-nlb-domain.com", 5000, new SslCredentials()); // aws nlb tls while (!shutdownCancellation.IsCancellationRequested) { try { Debug.Log($"Connecting to the server..."); this.streamingClient = await StreamingHubClient.ConnectAsync <IChatHub, IChatHubReceiver>(this.channel, this, cancellationToken : shutdownCancellation.Token); this.RegisterDisconnectEvent(streamingClient); Debug.Log($"Connection is established."); break; } catch (Exception e) { Debug.LogError(e); } Debug.Log($"Failed to connect to the server. Retry after 5 seconds..."); await Task.Delay(5 * 1000); } this.client = MagicOnionClient.Create <IChatService>(this.channel); }
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(); } }
public ChatClient(RichTextBox textBox) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); this.client = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(channel, this); this.textBox = textBox; }
public void Start() { this._isJoin = false; var channel = new Channel("localhost:8700", ChannelCredentials.Insecure); this._hub = StreamingHubClient.Connect <IChatHub, IChatHubReceiver>(channel, this); }
public async Task RetrunOneArgument() { var client = StreamingHubClient.Connect <ITestHub, IMessageReceiver>(channel, this); var v = await client.RetrunZeroArgument(); v.Is(1000); await client.DisposeAsync(); }
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; }
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(); }
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); }
/// <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()); }
public async Task Connect() { channel = GrpcChannel.ForAddress(address); serviceClient = MagicOnionClient.Create <ITodoService>(channel); notifyClient = await StreamingHubClient.ConnectAsync <ITodoNotify, ITodoNotifyReceiver>(channel, this); await notifyClient.Join(); manager = new TodoManager(await serviceClient.Get()); }
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(); }
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(); }
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(); }
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); }
// 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); }
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); }
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]); }
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(); }
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(); }
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(); }
// 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); }