private async static Task MainImpl() { var config = ClientConfiguration.ForAccount(ACCOUNTID, APPLICATIONNAME); var client = new Client(config); var scene = await client.GetPublicScene(SCENENAME, ""); var pendingRpcPing = 0; await scene.Connect(); //wait for the sync clock to synchronize. await Task.Delay(TimeSpan.FromSeconds(10)); var timer = Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(100)); var measures = new List <Measure>(); using (timer.Subscribe(async _ => { if (pendingRpcPing < _maxPendingRpcPings) { Interlocked.Increment(ref pendingRpcPing); var measure = new Measure(); measure.RequestTime = client.Clock; measure.ServerReceptionTime = await scene.RpcTask <object, long>("rpcping", null); measure.ReceptionTime = client.Clock; Interlocked.Decrement(ref pendingRpcPing); measures.Add(measure); } })) { await Task.Delay(600000); } //write the measures into a CSV using (var writer = File.CreateText("output.csv")) { foreach (var measure in measures) { writer.WriteLine($"{measure.RequestTime}, {measure.ServerReceptionTime}, {measure.ReceptionTime}"); } } }
public async Task Run(dynamic configuration, string[] args, Action <string, float> signalMetric, Action <string> error) { try { var config = ClientConfiguration.ForAccount((string)configuration.account, (string)configuration.application); config.ServerEndpoint = configuration.endpoint; var stopWatch = new Stopwatch(); stopWatch.Restart(); var client = new Client(config); var token = await CreateConnectionToken(config.ServerEndpoint, config.Account, config.Application, (string)configuration.scene, (string)configuration.secret); var scene = await client.GetScene(token); await scene.Connect(); var connectionTime = stopWatch.ElapsedMilliseconds; signalMetric("connectionDuration", connectionTime); var rpcResults = await scene.Rpc <string, Dictionary <string, float> >((string)configuration.rpc, (string)configuration.secret); var rpcTime = stopWatch.ElapsedMilliseconds; stopWatch.Stop(); signalMetric("rpcDuration", rpcTime - connectionTime); signalMetric("online", 1); foreach (var r in rpcResults) { signalMetric(r.Key, r.Value); } } catch (Exception ex) { signalMetric("online", 0); error(ex.Message); } }
private void InitClient() { if (string.IsNullOrEmpty(AccountId) || string.IsNullOrEmpty(ApplicationName)) { Debug.LogError("AccountId or Application name are not set. Cannot connect to remoteScene"); } var config = ClientConfiguration.ForAccount(AccountId, ApplicationName); if (ServerEndpoints.Any()) { config.ServerEndpoints = ServerEndpoints; } if (AuthenticationPlugin) { config.Plugins.Add(new AuthenticationPlugin()); } if (MatchmakingPlugin) { config.Plugins.Add(new MatchmakingPlugin()); } if (TransactionBroker) { config.Plugins.Add(new TransactionBrokerPlugin()); } if (ServerClockPlugin) { config.Plugins.Add(new ServerClockPlugin()); } if (LeaderboardPlugin) { config.Plugins.Add(new LeaderboardPlugin()); } if (ChatPlugin) { config.Plugins.Add(new ChatPlugin()); } if (FriendsPlugin) { config.Plugins.Add(new FriendsPlugin()); } if (ClientSettingsPlugin) { config.Plugins.Add(new ClientSettingsPlugin()); } if (GameVersionPlugin) { config.Plugins.Add(new GameVersionPlugin()); } if (DebugLog) { config.Logger = DebugLogger.Instance; } var action = OnClientConfiguration; if (action != null) { action(config); } _client = new Client(config); _client.OnDisconnected += InvokeDisonnected; UniRx.MainThreadDispatcher.Initialize(); }
public void Connect() { if (_connecting == true) { return; } if (connexionPanel.username.text == "") { connexionPanel.errorText.text = "please enter a user name."; } else { _connecting = true; Debug.Log("starting connection"); UniRx.MainThreadDispatcher.Initialize(); var Config = ClientConfiguration.ForAccount("7794da14-4d7d-b5b5-a717-47df09ca8492", "projectew2d"); var newClient = new Client(Config); client = newClient; localPlayer = new Player(0, connexionPanel.username.text, 0); localPlayer.ship = playerShip; localPlayer.color_red = connexionPanel.redSlider.value; localPlayer.color_blue = connexionPanel.blueSlider.value; localPlayer.color_green = connexionPanel.greenSlider.value; playerMarker.GetComponent <Renderer>().material.color = new Color(localPlayer.color_red, localPlayer.color_green, localPlayer.color_blue); playerShip.GetComponent <Renderer>().material.color = new Color(localPlayer.color_red, localPlayer.color_green, localPlayer.color_blue); Debug.Log("config complete"); client.GetPublicScene("test", (myGameObject)localPlayer).ContinueWith(task => { if (task.IsFaulted) { Debug.Log("connection failed, cannot get scene : " + task.Exception.Message); StormancerActionHandler.Post(() => { connexionPanel.errorText.text = "Connexion failed"; }); _connecting = false; } else { var newScene = task.Result; scene = newScene; Debug.Log("configuring routes"); scene.AddRoute("chat", onChat); scene.AddRoute("update_position", onUpdatePosition); scene.AddRoute("player_connected", onPlayerConnected); scene.AddRoute("player_disconnected", onPlayerDisconnected); scene.AddRoute("get_id", onGetId); scene.AddRoute("update_status", onUpdateStatus); scene.AddRoute("spawn_bullet", onBulletSpawn); scene.AddRoute("destroy_bullet", onBulletDestroyed); Debug.Log("connecting to remote scene"); scene.Connect().ContinueWith(t => { if (scene.Connected) { _connected = true; _connecting = false; Debug.Log("connection successful"); StormancerActionHandler.Post(() => { connexionPanel.gameObject.SetActive(false); playerShip.GetComponent <Renderer>().enabled = true; playerMarker.GetComponent <Renderer>().enabled = true; gamePaused = false; _connected = true; }); } else { Debug.Log("connection failed: " + t.Exception.InnerException.Message); _connecting = false; StormancerActionHandler.Post(() => { connexionPanel.errorText.text = "Connexion failed"; }); } }); } }); } }