我正在使用java.net.Socket进行套接字通信。我尝试了允许本地主机进行套接字通信的network-security-config.xml文件的解决方案。
我的代码段如下:
Socket socket = new Socket("192.168.1.1", "5000");
下面是我的network-security-config.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">http://192.168.1.1:5000</domain>
</domain-config>
我也尝试了以下代码段
1) Replace <domain includeSubdomains="true">http://192.168.1.1:5000</domain> to <domain includeSubdomains="true">http://localhost:5000</domain>
2) Replace <domain includeSubdomains="true">http://192.168.1.1:5000</domain> to <domain includeSubdomains="true">localhost</domain>
但是以上解决方案均无效。可能是我错过了一些东西。
如果有人对此问题有经验。请提供解决方案。
感谢您的帮助。