示例#1
0
    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);
    }
示例#2
0
        /// <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");
                }
            }
        }
示例#3
0
        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;
        }
示例#4
0
 /// <summary>
 /// Kill the connection to your EdgeMultiplay server
 /// </summary>
 public static void Disconnect()
 {
     wsClient  = null;
     udpClient = null;
     foreach (NetworkedPlayer player in currentRoomPlayers)
     {
         Destroy(player.gameObject);
     }
     currentRoomPlayers = new List <NetworkedPlayer>();
     gameSession        = new Session();
     gameStarted        = false;
     MessageSender      = null;
     localPlayer        = null;
     observers          = new List <EdgeMultiplayObserver>();
 }
示例#5
0
        // 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());
        }
示例#6
0
        string edgeCloudletStr = ""; // Connection url to Edge


        #region MonoBehaviour Callbacks
        // Use this for initialization
        IEnumerator Start()
        {
            integration = new MobiledgeXIntegration();
            // 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
            yield return(StartCoroutine(MobiledgeX.LocationService.EnsureLocation()));

            MobiledgeXAPICalls();

            // Use local server, by IP. This must be started before use:
            if (useAltServer)
            {
                host = altServerHost;
            }

            server = "ws://" + host + ":" + port;

            webSocketClient       = new MobiledgeXWebSocketClient();
            gameSession           = new GameSession();
            gameSession.currentGs = new GameState();
            gameSession.status    = STATUS.LOBBY;
        }