// This method is called when the user has finished editing the Room ID InputField. public async void ConnectToServerWithRoomId(string roomId) { Uri edgeCloudletUri; if (roomId == "") { gameManager.clog("You must enter a room ID. Please try again."); return; } gameManager.clog("Connecting to WebSocket Server with roomId=" + roomId + "..."); gameManager.clog("useAltServer=" + useAltServer + " host=" + host + " edgeCloudletStr=" + edgeCloudletStr); queryParams = "?roomid=" + roomId; if (webSocketClient.isOpen()) { webSocketClient.Dispose(); webSocketClient = new MobiledgeXWebSocketClient(); } if (useAltServer) { server = "ws://" + host + ":" + port; edgeCloudletUri = new Uri(server + queryParams); await webSocketClient.Connect(edgeCloudletUri); } else { try { edgeCloudletUri = new Uri(edgeCloudletStr + queryParams); await webSocketClient.Connect(edgeCloudletUri); } catch (Exception e) { gameManager.clog("Unable to get websocket connection. Exception: " + e.Message + ". Switching to AltServer."); useAltServer = true; ConnectToServerWithRoomId(roomId); return; } } gameManager.clog("Connection to status: " + webSocketClient.isOpen()); }
async Task StartWebSocket(string url) { wsClient = new MobiledgeXWebSocketClient(); if (wsClient.isOpen()) { wsClient.Dispose(); wsClient = new MobiledgeXWebSocketClient(); } Uri uri = new Uri(url); await wsClient.Connect(uri); }
/// <summary> /// Connect to your EdgeMultiplay server based on location and carrier info /// <para> /// use <b>public override void OnConnectionToEdge()</b> to get the server response /// </para> /// </summary> /// <param name="useAnyCarrierNetwork"> set to true for connection based on location info only </param> /// <param name="useFallBackLocation"> set to true to use overloaded location sat in setFallbackLocation()</param> /// <param name="path"> You can specify a path for your connection to be verified on the server side </param> /// <returns> Connection Task, use OnConnectionToEdge() to listen to the async task result </returns> public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFallBackLocation = false, string path = "") { if (useLocalHostServer) { try { gameSession = new Session(); wsClient = new MobiledgeXWebSocketClient(); Uri uri = new Uri("ws://" + hostIPAddress + ":" + defaultEdgeMultiplayServerTCPPort + path); if (wsClient.isOpen()) { wsClient.Dispose(); wsClient = new MobiledgeXWebSocketClient(); } await wsClient.Connect(@uri); EdgeMultiplayCallbacks.connectedToEdge(); } catch (Exception e) { EdgeMultiplayCallbacks.failureToConnect(e.Message); Debug.LogError("EdgeMultiplay: Failed to connect to your Local Host, Check console for more details"); } } else { try { gameSession = new Session(); integration.UseWifiOnly(useAnyCarrierNetwork); integration.useFallbackLocation = useFallBackLocation; wsClient = new MobiledgeXWebSocketClient(); await integration.RegisterAndFindCloudlet(); integration.GetAppPort(LProto.L_PROTO_TCP); string url = integration.GetUrl("ws") + path; Uri uri = new Uri(url); if (wsClient.isOpen()) { wsClient.Dispose(); wsClient = new MobiledgeXWebSocketClient(); } await wsClient.Connect(@uri); EdgeMultiplayCallbacks.connectedToEdge(); } catch (Exception e) { EdgeMultiplayCallbacks.failureToConnect(e.Message); Debug.LogError("EdgeMultiplay: Failed to connect to Edge, Check console for more details"); } } }
public async void StartWs(string url) { Uri uri = new Uri(url); client = new MobiledgeXWebSocketClient(); if (client.isOpen()) { client.Dispose(); client = new MobiledgeXWebSocketClient(); } await client.Connect(uri); appManager.wsStarted = true; }