我在连接到本地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)
我已经看过这篇文章了
我尝试了所有的方法,添加权限到我的AndroidManifest.xml,卸载,使用过的物理电话等等,但都不起作用。
这可能是我的代码,我已经尝试寻找AsyncTask的替代方法。所以可能是代码写错了。希望有人能帮帮我。
MainActivity:
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);
}
}
});
}
});
}发布于 2021-05-28 16:03:31
我想通了。这是一个愚蠢的IP地址错误,应该在以前看到过。我只需将IP地址更改为我所连接的电话上的IP地址(192.168.10.15)。
https://stackoverflow.com/questions/67695193
复制相似问题