我在连接到 IP 时遇到错误(套接字失败:EPERM)

I am getting an error connecting to IP (Socket failed: EPERM)

我无法连接到从 Android Studio 中的 emulator/phone 连接到我的 KNX 网络的本地 Web 界面 (192.168.10.13:3671)。 我尝试使用一个名为 KNXwizard 的已经开发的应用程序连接到相同的 Web 界面并且可以正常工作,但我在代码中看到该应用程序使用 AsyncTask.

总是出现此错误:Error creating KNXnet/IP tunneling link: tuwien.auto.calimero.KNXException: connecting from /192.168.163.198:3671 to /192.168.10.13:3671: socket failed: EPERM (Operation not permitted)

我查看过这个帖子

Socket failed 1

那里的一切都试过了,为我的 AndroidManifest.xml 添加了权限,卸载了,使用了物理 phone 等等。但是没有任何效果。

这可能是我的代码,我已经尝试搜索 AsyncTask 的替代方法。所以可能是代码写错了。希望有人能帮帮我。

主要活动:

public class MainActivity extends AppCompatActivity {

private static InetSocketAddress local = new InetSocketAddress("192.168.163.198", 3671);
private static InetSocketAddress server = new InetSocketAddress("192.168.10.13",
        KNXnetIPConnection.DEFAULT_PORT);





Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button)findViewById(R.id.button);

    ExecutorService executorService = Executors.newSingleThreadExecutor();




    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            executorService.execute(new Runnable() {
                @Override
                public void run() {


                    //doInBackground
                    System.out.println("This example establishes a tunneling connection to the KNXnet/IP server " + server);

                    // A KNX tunneling link supports NAT (Network Address Translation) if required.
                    // We also indicate that the KNX installation uses twisted-pair (TP) medium, with TP1 being the most common.
                    // KNXNetworkLink is the base interface implemented by all supported Calimero links to a KNX network.
                    try (KNXNetworkLink knxLink = KNXNetworkLinkIP.newTunnelingLink(local, server, false, TPSettings.TP1)) {
                        System.out.println("Connection established to server " + knxLink.getName());
                        System.out.println("Close connection again");
                    } catch (KNXException | InterruptedException e) {
                        // KNXException: all Calimero-specific checked exceptions are subtypes of KNXException

                        // InterruptedException: longer tasks that might block are interruptible, e.g., connection procedures. In
                        // such case, an instance of InterruptedException is thrown.
                        // If a task got interrupted, Calimero will clean up its internal state and resources accordingly.
                        // Any deviation of such behavior, e.g., where not feasible, is documented in the Calimero API.

                        System.out.println("Error creating KNXnet/IP tunneling link: " + e);

                    }
                }


            });
        }


    });
}

我想通了。 IP 地址是一个愚蠢的错误,之前应该已经看到了。我只是将 IP 地址更改为我连接到的 phone 上的 IP 地址 (192.168.10.15)。