【发布时间】:2021-08-14 02:58:12
【问题描述】:
我无法从Android Studio 中的模拟器/电话连接到连接到我的 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)
我已经查看了这些帖子
在那里尝试了所有方法,为我的AndroidManifest.xml 添加了权限,卸载了,使用了物理手机等。但没有任何效果。
这可能是我的代码,我尝试为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);
}
}
});
}
});
}
【问题讨论】:
-
你测试的是什么 api 级别?
-
android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 23 targetSdkVersion 30 versionCode 1 versionName "1.0" -
仅仅因为您使用 Android Studio 开发应用程序并启动 AVD 并不意味着执行连接的是 Android Studio 本身。 AVD 模拟器实际上是标准 Android SDK 的一部分,Android Studio 只是在它之上提供了一个不错的 GUI。如果您愿意,可以按照this article 中的建议安装 SDK 并在不使用 Android Studio 的情况下设置 AVD。
-
I have trouble with connecting to a web server....请编辑您的帖子并立即通知我们您的服务器在哪里运行。也可以删除一些cmets。
标签: android sockets executorservice