示例#1
0
        }//发送指令

        private async void UpLoadData(int PortNum, Router.Controller.FileIO Obj)
        {
            try
            {
                string[] DataQune = await Obj.PoPToCloud();//Obj.PoPOut();PoPToCloud();

                foreach (var item in DataQune)
                {
                    string content = "";
                    if (RSAFlag == true)
                    {
                        content = RSAConvert.PublicEncrypt(item);//RSA加密
                    }
                    else
                    {
                        content = item;
                    }
                    if (AZureFlag == true)//使用AZure IoT
                    {
                        await AzureIoTHub.SendDeviceToCloudMessageAsync(item);
                    }

                    if (string.IsNullOrEmpty(content))
                    {
                        continue;
                    }
                    using (DatagramSocket socket = new DatagramSocket())
                    {
                        HostName      broardaddr = new HostName(IPAddress.Broadcast.ToString());
                        IOutputStream outstream  = await socket.GetOutputStreamAsync(broardaddr, PortNum.ToString());

                        DataWriter writer = new DataWriter(outstream);
                        writer.UnicodeEncoding = UnicodeEncoding.Utf8;
                        uint len = writer.MeasureString(content);
                        writer.WriteUInt32(len);
                        writer.WriteString(content);
                        await writer.StoreAsync();

                        writer.Dispose();
                    }
                }
            }
            catch (Exception) { }
        }//向云上传数据