首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接到IP时出现错误(套接字失败: EPERM)

连接到IP时出现错误(套接字失败: EPERM)
EN

Stack Overflow用户
提问于 2021-05-26 04:26:04
回答 1查看 77关注 0票数 1

我在连接到本地web接口(192.168.10.13:3671)时遇到了问题,这些接口是从Android Studio中的模拟器/电话连接到我的KNX网络的。我已经开发了一个名为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

Socket failed 2

我尝试了所有的方法,添加权限到我的AndroidManifest.xml,卸载,使用过的物理电话等等,但都不起作用。

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

MainActivity:

代码语言:javascript
复制
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);

                    }
                }


            });
        }


    });
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-28 16:03:31

我想通了。这是一个愚蠢的IP地址错误,应该在以前看到过。我只需将IP地址更改为我所连接的电话上的IP地址(192.168.10.15)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67695193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档