Can't connect to HTTP API hosted in laptop

I'm currently developing an application that connects to an API hosted on my laptop computer. Everything worked fine in December, and I could connect to my laptop from the Unity app using ML2. However, after some updates with the ML2 setup tool in Unity, I'm unable to connect via the Unity app, although I can still connect through ML2's web browser. I suspect there might be an additional configuration option that needs to be set up after these updates that I'm currently overlooking. Alternatively, I considered reverting to the previous version of the ML2 setup tool (version 2.4.0) that I used before, but it appears that downgrading isn't possible.

This new application is within a fresh Unity project based on the old one, and the APK from the previous project (utilizing the older setup tool version) continues to function properly. No modifications have been made to the API connection setup in the new application.

Unity Editor version: 2022.3.10f1
ML2 OS version: 1.4.0-dev2
Unity SDK version: 1.12.1
Host OS: Windows 10

The Magic Leap uses the standard Android API to perform network communication. You may want to verify that your application has the required network permissions before trying to connect to the remote device.

Regarding the setup tool, this tool should not have impacted the network communication, as it only configures the app as specified on the Getting Started Sections :

If you have your project in source control, you can look at the diff between the two project versions of the project setting.

Hi,

May I ask what are the required permissions for establishing an HTTP connection? What I had so far:

  1. Players - Other Settings - Allow downloads over HTTP -> set to "Always allowed"
  2. Players - Other Settings - Internet Access -> set to "Require"
  3. AndroidManifest.xml -> added <uses-permission android:name="android.permission.INTERNET" />

I have a code like this but cannot connect to the python flask server:

using UnityEngine;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using UnityEngine.Networking;

public class AsyncImageSender : MonoBehaviour
{
    private class ImageSendItem
    {
        public Texture2D Texture { get; set; }
        public long Timestamp { get; set; }
    }

    private Queue<ImageSendItem> imageQueue = new Queue<ImageSendItem>();
    private bool isProcessing = false;
    private CancellationTokenSource cts;
    private const string serverUrl = "{ip_address}:5000/upload";

    private void Start()
    {
        cts = new CancellationTokenSource();
    }

    private void OnDisable()
    {
        cts.Cancel();
        imageQueue.Clear();
    }

    public void QueueImageForSending(Texture2D texture, long timestamp)
    {
        imageQueue.Enqueue(new ImageSendItem { Texture = texture, Timestamp = timestamp });
        if (!isProcessing)
        {
            ProcessQueue();
        }
    }

    private async void ProcessQueue()
    {
        isProcessing = true;
        while (imageQueue.Count > 0 && !cts.IsCancellationRequested)
        {
            ImageSendItem item = imageQueue.Dequeue();
            await SendImageAsync(item.Texture, item.Timestamp);
        }
        isProcessing = false;
    }

    private async Task SendImageAsync(Texture2D texture, long timestamp)
    {
        try
        {
            byte[] pngData = await Task.Run(() => texture.EncodeToPNG(), cts.Token);

            WWWForm form = new WWWForm();
            form.AddBinaryData("screenshot", pngData, $"Image_{timestamp}.png", "image/png");

            using (UnityWebRequest www = UnityWebRequest.Post(serverUrl, form))
            {
                var operation = www.SendWebRequest();

                while (!operation.isDone)
                {
                    if (cts.IsCancellationRequested)
                    {
                        www.Abort();
                        throw new System.OperationCanceledException();
                    }
                    await Task.Yield();
                }

                if (www.result == UnityWebRequest.Result.Success)
                {
                    Debug.Log($"Image {timestamp} sent successfully");
                }
                else
                {
                    throw new System.Exception($"Error sending image: {www.error}");
                }
            }
        }
        catch (System.OperationCanceledException)
        {
            Debug.Log("Image sending cancelled.");
        }
        catch (System.Exception e)
        {
            Debug.LogError($"Error sending image: {e.Message}");
        }
    }
}

I had a previously implemented TCP connection code which still worked fine in the current Unity SDK version (2.5.0) and current OS (1.9.0).

Your setup seems correct in terms of permissions for enabling HTTP communication in Android using Unity. However, the issue might not just be related to permissions but could involve things like the server address format, UnityWebRequest settings, or the Flask server configuration.

Since this issue is not Magic Leap 2 specific it might be best for you to consult Unity's official Forum or Discussion channels since our knowledge base on general Unity issues is limited.