// This method is called when the user has finished editing the Room ID InputField. async void ConnectToServerWithRoomId(string roomId) { Uri edgeCloudletUri; if (roomId == "") { clog("You must enter a room ID. Please try again."); return; } clog("Connecting to WebSocket Server with roomId=" + roomId + "..."); clog("useAltServer=" + useAltServer + " host=" + host + " edgeCloudletStr=" + edgeCloudletStr); queryParams = "?roomid=" + roomId; if (client.isOpen()) { client.Dispose(); client = new WsClient(integration); } if (useAltServer) { server = "ws://" + host + ":" + port; edgeCloudletUri = new Uri(server + queryParams); await client.Connect(edgeCloudletUri); } else { await client.Connect(queryParams); } clog("Connection to status: " + client.isOpen()); }
// Use this for initialization async Task Start() { // Demo mode DME server to run MobiledgeX APIs, or if SIM card is missing // and a local DME cannot be located. Set to false if using a supported // SIM Card. integration = new MobiledgeXIntegration(); integration.useDemo = true; integration.dmeHost = integration.me.GenerateDmeHostName(); // Use local server, by IP. This must be started before use: if (useAltServer) { host = altServerHost; } server = "ws://" + host + ":" + port; theBall = GameObject.FindGameObjectWithTag("Ball"); players = GameObject.FindGameObjectsWithTag("Player"); client = new WsClient(); gameSession.currentGs = new GameState(); gameSession.status = STATUS.LOBBY; // Create a Mex Paddle (for local user) from the Prefab: ghostPlayer = (GameObject)Instantiate(Resources.Load("PaddleGhost")); ghostBall = (GameObject)Instantiate(Resources.Load("BallGhost")); uiG = GameObject.FindGameObjectWithTag("UIConsole"); uiConsole = uiG.GetComponent <Text>(); // Attach a listener to the Room ID input field. roomIdInput = GameObject.Find("InputFieldRoomId").GetComponent <InputField>(); roomIdInput.onEndEdit.AddListener(ConnectToServerWithRoomId); try { // Register and find cloudlet: uiConsole.text = "Registering to DME: "; edgeCloudletStr = await RegisterAndFindCloudlet(); stopWatch.Start(); clog("Found Cloudlet from DME result: [" + edgeCloudletStr + "]"); // This might be inside a thread update loop. Re-register client and check periodically. // VerifyLocation will fail if verification is unavailable at the carrier. bool verifiedLocation = await integration.VerifyLocation(); //bool verifiedLocation = false; // Decide what to do with location status. clog("VerifiedLocation: " + verifiedLocation); } catch (HttpException httpe) // HTTP status, and REST API call error codes. { // server error code, and human readable message: clog("RegisterClient Exception: " + httpe.Message + ", HTTP StatusCode: " + httpe.HttpStatusCode + ", API ErrorCode: " + httpe.ErrorCode + "\nStack: " + httpe.StackTrace); } catch (DmeDnsException de) { // This app should fallback to public cloud, as the DME doesn't exist for your // SIM card + carrier. clog("Cannot register to DME host: " + de.Message + ", Stack: " + de.StackTrace); if (de.InnerException != null) { clog("Original Exception: " + de.InnerException.Message); } // Handle fallback to public cloud application server. } catch (HttpRequestException httpre) { clog("RegisterClient HttpRequest Exception" + httpre.Message + "\nStack Trace: " + httpre.StackTrace); } catch (Exception e) { clog("Unexpected Exception: " + e.StackTrace); } }