getConnectionState() 根据设备连接/断开。如果它正在发送消息,我应该看到已连接,如果它不发送,我应该断开连接。但是每次我运行下面的 java 程序时,无论设备是什么,我都会得到断开连接的状态是否发送消息
RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
System.out.println(registryManager.getDevices(new Integer(1000)));
while(true){
ArrayList<Device> deviceslist=registryManager.getDevices(new Integer(1000));
for(Device device:deviceslist)
{
/*System.out.println(device.getDeviceId());
System.out.println(device.getPrimaryKey());
System.out.println(device.getSecondaryKey());*/
System.out.println(device.getDeviceId());
System.out.println(device.getConnectionState());
/*System.out.println(device.getConnectionStateUpdatedTime());
System.out.println(device.getLastActivityTime());
System.out.println(device.getStatusReason());
System.out.println(device.getStatusUpdatedTime());
System.out.println(device.getSymmetricKey());
System.out.println(device.geteTag());
*/ }
}
我肯定不这么看。
我正在使用下面的代码创建一个简单的 C# 控制台应用程序,
static async void QueryDevices()
{
RegistryManager manager = RegistryManager.CreateFromConnectionString(connectionString);
while (true)
{
var devices = await manager.GetDevicesAsync(100);
{
foreach (var item in devices)
{
Console.WriteLine(DateTime.Now + ": " + item.Id + ", " + item.ConnectionState);
System.Threading.Thread.Sleep(100);
}
}
}
}
这里的 git 总是查询整个设备列表,因为 ConnectionState 属性在某种程度上看起来像单个设备客户端实例的“静态”成员,即使实际状态发生变化,它也不容易改变。
我的输出如下所示,“已连接”状态是当我使用 java 客户端示例向 IoT 中心发送消息时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)