private static SpectatorClient getConnectedClient() { var connection = new HubConnectionBuilder() .AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }) .WithUrl("http://localhost:5009/spectator") .ConfigureLogging(logging => { logging.AddFilter("Microsoft.AspNetCore.SignalR", LogLevel.Debug); logging.AddConsole(); }) .Build(); var client = new SpectatorClient(connection); connection.Closed += async(error) => { Console.WriteLine($"Connection closed with error:{error}"); await connection.StartAsync(); }; connection.Reconnected += id => { Console.WriteLine($"Connected with id:{id}"); return(Task.CompletedTask); }; while (true) { try { connection.StartAsync().Wait(); break; } catch { // try until connected } } Console.WriteLine($"client {connection.ConnectionId} connected!"); return(client); }
private static SpectatorClient getConnectedClient() { var connection = new HubConnectionBuilder() .AddMessagePackProtocol() .WithUrl("http://localhost:80/spectator") .ConfigureLogging(logging => { logging.AddFilter("Microsoft.AspNetCore.SignalR", LogLevel.Debug); logging.AddConsole(); }) .Build(); var client = new SpectatorClient(connection); connection.Closed += async error => { Console.WriteLine($"Connection closed with error:{error}"); await connection.StartAsync(); }; connection.Reconnected += id => { Console.WriteLine($"Connected with id:{id}"); return(Task.CompletedTask); }; while (true) { try { connection.StartAsync().Wait(); break; } catch { // try until connected } } Console.WriteLine($"client {connection.ConnectionId} connected!"); return(client); }