当前位置: 首页>>代码示例>>C#>>正文


C# DataWriter.WriteUInt32方法代码示例

本文整理汇总了C#中Windows.Storage.Streams.DataWriter.WriteUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.WriteUInt32方法的具体用法?C# DataWriter.WriteUInt32怎么用?C# DataWriter.WriteUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.Streams.DataWriter的用法示例。


在下文中一共展示了DataWriter.WriteUInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: send

        /// <summary>
        /// Send the message to the server
        /// </summary>
        /// <param name="type">KB or M</param>
        /// <param name="message">Single character or x,y</param>
        /// <param name="hold">0=default, 1=press, 2=release</param>
        public void send(string type, string message, int hold = 0)
        {
            try
            {
                //NetworkStream clientStream = client.GetStream();
                DataWriter writer = new DataWriter(client.OutputStream);

                
                //ASCIIEncoding encoder = new ASCIIEncoding();

                string buffer = type + ';' + message + ';' + hold + "\n";
                writer.WriteUInt32(writer.MeasureString(buffer));
                writer.WriteString(buffer);
                /*
                clientStream.Write(buffer, 0, buffer.Length);
                clientStream.Flush();
                 * */
                writer.WriteString(buffer);
            }
            catch
            {
                //Console.WriteLine("Connection Lost");
                startClient();
            }
        }
开发者ID:j0z,项目名称:PlayM,代码行数:31,代码来源:Client.cs

示例2: OnWrite

 private async void OnWrite(Object sender, RoutedEventArgs e)
 {
     // 获取本地目录的引用
     StorageFolder local = ApplicationData.Current.LocalFolder;
     // 创建新文件
     StorageFile newFIle = await local.CreateFileAsync("demo.dat", CreationCollisionOption.ReplaceExisting);
     // 打开文件流
     using(IRandomAccessStream stream = await newFIle.OpenAsync(FileAccessMode.ReadWrite))
     {
         // 实例化 DataWriter
         DataWriter dw = new DataWriter(stream);
         // 设置默认编码格式
         dw.UnicodeEncoding = UnicodeEncoding.Utf8;
         // 写入 bool 值
         dw.WriteBoolean(true);
         // 写入日期值
         DateTime dt = new DateTime(2010, 8, 21);
         dw.WriteDateTime(dt);
         // 写入字符串
         string str = "测试文本";
         // 计算字符串长度
         uint len = dw.MeasureString(str);
         // 先写入字符串的长的
         dw.WriteUInt32(len);
         // 再写入字符串
         dw.WriteString(str);
         // 以下方法必须调用
         await dw.StoreAsync();
         // 解除 DataWriter 与流的关联
         dw.DetachStream();
         dw.Dispose();
     }
     MessageDialog msgDlg = new MessageDialog("保存成功。");
     await msgDlg.ShowAsync();
 }
开发者ID:forehalo,项目名称:UWP-dev,代码行数:35,代码来源:_DataWriter.xaml.cs

示例3: ConnectToPeer

 /// <summary>
 /// 连接并发送信息给对方
 /// </summary>
 /// <param name="peerInformation"></param>
 private async void ConnectToPeer(PeerInformation peer)
 {
     dataReader = new DataReader(socket.InputStream);
     dataWriter = new DataWriter(socket.OutputStream);
     string message = "测试消息";
     uint strLength = dataWriter.MeasureString(message);
     dataWriter.WriteUInt32(strLength);
     dataWriter.WriteString(message);
     uint numBytesWritten = await dataWriter.StoreAsync();
 }
开发者ID:745322878,项目名称:Code,代码行数:14,代码来源:MainPage.xaml.cs

示例4: sendMail

 public async void sendMail(string strSendTo,string strContent , Boolean hasPicture)
 {
     HostName hostName = new HostName(hostIP);
     StreamSocket socket = new StreamSocket();
     List<string[]> storeList = new List<string[]>();
     try
     {
         await socket.ConnectAsync(hostName, port);
     }
     catch (Exception exception)
     {
         if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
         {
             throw;
         }
     }
     StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Temp");
     StorageFile pic = await folder.GetFileAsync("MyPainter.png");
     IBuffer buffer = await FileIO.ReadBufferAsync(pic);
     DataWriter writer = new DataWriter(socket.OutputStream);
     writer.WriteUInt32(writer.MeasureString(strSendTo));
     writer.WriteString(strSendTo);
     writer.WriteUInt32(writer.MeasureString(strContent));
     writer.WriteString(strContent);
     if (hasPicture)
     {
         writer.WriteUInt32((uint)buffer.Length);
         writer.WriteBuffer(buffer);
     }
     else
     {
         writer.WriteUInt32(0);
         writer.WriteString("");
     }
     await writer.StoreAsync();
     writer.DetachStream();
     writer.Dispose();
     socket.Dispose();
 }
开发者ID:IcePlus,项目名称:KidsPainter,代码行数:39,代码来源:SendMail.cs

示例5: Button_Click

 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     string message = txtSend.Text;
     DataWriter writer = new DataWriter(socket.OutputStream);
     var length = writer.MeasureString(message);
     writer.WriteUInt32(length);
     //将字符串写入流中
     writer.WriteString(message);
     //向服务器发送数据
     await writer.StoreAsync();
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
         textList.Items.Add(message);
     });
 }
开发者ID:fqncom,项目名称:tomcraporigami,代码行数:14,代码来源:MainPage.xaml.cs

示例6: streamSocketListener_ConnectionReceived

        async void streamSocketListener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            int i = 0;
            DataReader dataReader = new DataReader(args.Socket.InputStream);
            DataWriter serverWriter = new DataWriter(args.Socket.OutputStream);
            try
            {
                while (true)
                {
                    uint sizeCount = await dataReader.LoadAsync(4);
                    uint length = dataReader.ReadUInt32();
                    uint contentLength = await dataReader.LoadAsync(length);
                    string msg = dataReader.ReadString(contentLength);
                    i++;
                    Deployment.Current.Dispatcher.BeginInvoke(() => msgList.Children.Add(
                        new TextBlock { Text = "服务器接收到的消息:" + msg }));
                    string serverStr = msg + "|" + i;
                    serverWriter.WriteUInt32(serverWriter.MeasureString(serverStr));
                    serverWriter.WriteString(serverStr);
                    try
                    {
                        await serverWriter.StoreAsync();
                    }
                    catch (Exception err)
                    {
                        if (SocketError.GetStatus(err.HResult) == SocketErrorStatus.AddressAlreadyInUse)
                        {

                        }
                    }
                }
            }
            catch (Exception err)
            {
                if (SocketError.GetStatus(err.HResult) == SocketErrorStatus.AddressAlreadyInUse)
                {

                }
            }
        }
开发者ID:peepo3663,项目名称:WindowsPhone8,代码行数:40,代码来源:MainPage.xaml.cs

示例7: WriteString

        public async void WriteString(string HostName, string Message)
        {
            HostName remoteHostName = new HostName(HostName);

            using (StreamSocket socket = new StreamSocket())
            {
                socket.Control.KeepAlive = false;
                await socket.ConnectAsync(remoteHostName, "6");

                using (DataWriter writer = new DataWriter(socket.OutputStream))
                {
                    // set payload length
                    writer.ByteOrder = ByteOrder.LittleEndian;
                    writer.WriteUInt32(writer.MeasureString(Message));
                    // set payload type
                    writer.WriteByte((byte)PayloadType.String);
                    // set payload
                    writer.WriteString(Message);
                    // transmit
                    await writer.StoreAsync();
                    writer.DetachStream();
                }

                using (DataReader reader = new DataReader(socket.InputStream))
                {
                    int length;
                    string response;
                    // receive payload length
                    reader.ByteOrder = ByteOrder.LittleEndian;
                    await reader.LoadAsync(4);
                    length = reader.ReadInt32();
                    // receive payload
                    await reader.LoadAsync((uint)length);
                    response = reader.ReadString((uint)length);

                    Debug.WriteLine(string.Format("response: {0}", response));
                    reader.DetachStream();
                }
            }
        }
开发者ID:cyberh0me,项目名称:IoT,代码行数:40,代码来源:TCP.cs

示例8: TcpService_ConnectionReceived

        private async void TcpService_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            using (var client = args.Socket)
            using (var dr = new DataReader(client.InputStream))
            using (var dw = new DataWriter(client.OutputStream))
            {
                await dr.LoadAsync(sizeof(Int32));
                var messageLenght = dr.ReadUInt32();

                await dr.LoadAsync(messageLenght);
                var bytes = new Byte[messageLenght];
                dr.ReadBytes(bytes);

                var request = Encoding.UTF8.GetString(bytes);
                var response = "Успешно получено";

                var body = Encoding.UTF8.GetBytes(response);
                dw.WriteUInt32((UInt32)body.Length);
                dw.WriteBytes(body);
                await dw.StoreAsync();
            }
        }
开发者ID:PRIESt512,项目名称:Beowulf,代码行数:22,代码来源:MainPage.xaml.cs

示例9: SaveTo

		public static async void SaveTo ( ObservableCollection<RecentData> datas )
		{
			StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync ( "data.dat",
				Windows.Storage.CreationCollisionOption.ReplaceExisting );
			FileRandomAccessStream stream = await sf.OpenAsync ( FileAccessMode.ReadWrite ) as FileRandomAccessStream;
			DataWriter dw = new DataWriter ( stream );

			dw.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
			dw.ByteOrder = ByteOrder.LittleEndian;

			dw.WriteInt32 ( datas.Count );
			foreach ( RecentData data in datas )
			{
				dw.WriteUInt32 ( ( uint ) dw.MeasureString ( data.Source ) );
				dw.WriteString ( data.Source );
				dw.WriteInt32 ( data.SourceIndex );
				dw.WriteInt32 ( data.TargetIndex );
			}

			await dw.StoreAsync ();
			await dw.FlushAsync ();
			stream.Dispose ();
		}
开发者ID:Daramkun,项目名称:LangTrans,代码行数:23,代码来源:DataManager.cs

示例10: Reboot

        public async void Reboot(string HostName)
        {
            HostName remoteHostName = new HostName(HostName);

            using (StreamSocket socket = new StreamSocket())
            {
                socket.Control.KeepAlive = false;
                await socket.ConnectAsync(remoteHostName, "6");

                using (DataWriter writer = new DataWriter(socket.OutputStream))
                {
                    // set payload length
                    writer.ByteOrder = ByteOrder.LittleEndian;
                    writer.WriteUInt32(2);
                    // set payload type
                    writer.WriteByte((byte)PayloadType.Byte);
                    // set payload
                    writer.WriteByte(0x01);
                    // transmit
                    await writer.StoreAsync();
                    writer.DetachStream();
                }
            }
        }
开发者ID:cyberh0me,项目名称:IoT,代码行数:24,代码来源:TCP.cs

示例11: SendSocket_Click

        private async void SendSocket_Click(object sender, RoutedEventArgs e)
        {
            using (var socket = new StreamSocket())
            using (var dw = new DataWriter(socket.OutputStream))
            using (var dr = new DataReader(socket.InputStream))
            {
                var end = new EndpointPair(
                    localHostName: new HostName("localhost"), localServiceName: String.Empty,
                    remoteHostName: new HostName("localhost"), remoteServiceName: "50000");

                //await socket.ConnectAsync(new HostName("localhost"), "8080");
                await socket.ConnectAsync(end);

                var message = Message.Text;
                var body = Encoding.UTF8.GetBytes(message);

                dw.WriteUInt32((UInt32)body.Length);
                dw.WriteBytes(body);
                await dw.StoreAsync();

                await dr.LoadAsync(sizeof(Int32));
                var response = dr.ReadString(100);
            }
        }
开发者ID:PRIESt512,项目名称:Beowulf,代码行数:24,代码来源:MainPage.xaml.cs

示例12: InternalSendMessage

        private async Task InternalSendMessage(Command cmd, DataWriter writer)
        {
            if(cmd == null)
            {
                return;
            }

            if(cmd.Program == GlowPrograms.None)
            {
                throw new Exception("The program can't be none!");
            }

            // Serialize the cmd
            string cmdJson = Newtonsoft.Json.JsonConvert.SerializeObject(cmd);
            UInt32 stringSize = writer.MeasureString(cmdJson);
            writer.WriteUInt32(stringSize);
            writer.WriteString(cmdJson);
            await writer.StoreAsync();
        }
开发者ID:QuinnDamerell,项目名称:Glow,代码行数:19,代码来源:CommandServer.cs

示例13: Send

        public async void Send(string s)
        {
            if (deviceService != null)
            {
                //send data
                string sendData = s;
                if (string.IsNullOrEmpty(sendData))
                {
                    //errorStatus.Visibility = Visibility.Visible;
                    errorStatusText = "Please specify the string you are going to send";
                    Debug.WriteLine("CommunicationChannelBT: " + errorStatusText);
                }
                else
                {
                    DataWriter dwriter = new DataWriter(streamSocket.OutputStream);
                    UInt32 len = dwriter.MeasureString(sendData);
                    dwriter.WriteUInt32(len);
                    dwriter.WriteString(sendData);
                    await dwriter.StoreAsync();
                    await dwriter.FlushAsync();
                }

            }
            else
            {
                //errorStatus.Visibility = Visibility.Visible;
                errorStatusText = "Bluetooth is not connected correctly!";
                Debug.WriteLine("CommunicationChannelBT: " + errorStatusText);
            }
        }
开发者ID:slgrobotics,项目名称:Win10Bot,代码行数:30,代码来源:CommunicationChannelBT.cs

示例14: btnAddIe_Click

        private void btnAddIe_Click(object sender, RoutedEventArgs e)
        {
            if (_publisher == null)
            {
                _publisher = new WiFiDirectAdvertisementPublisher();
            }

            if (txtInformationElement.Text == "")
            {
                rootPage.NotifyUser("Please specifiy an IE", NotifyType.ErrorMessage);
                return;
            }

            WiFiDirectInformationElement IE = new WiFiDirectInformationElement();

            // IE blob
            DataWriter dataWriter = new DataWriter();
            dataWriter.UnicodeEncoding = UnicodeEncoding.Utf8;
            dataWriter.ByteOrder = ByteOrder.LittleEndian;
            dataWriter.WriteUInt32(dataWriter.MeasureString(txtInformationElement.Text));
            dataWriter.WriteString(txtInformationElement.Text);
            IE.Value = dataWriter.DetachBuffer();

            // OUI
            DataWriter dataWriterOUI = new DataWriter();
            dataWriterOUI.WriteBytes(Globals.CustomOui);
            IE.Oui = dataWriterOUI.DetachBuffer();

            // OUI Type
            IE.OuiType = Globals.CustomOuiType;

            _publisher.Advertisement.InformationElements.Add(IE);
            txtInformationElement.Text = "";

            rootPage.NotifyUser("IE added successfully", NotifyType.StatusMessage);
        }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:36,代码来源:Scenario1_Advertiser.xaml.cs

示例15: sendMessage

        private async Task sendMessage(string message)
        {
            if (_streamsocket == null)
            {
                this.textboxDebug.Text += "No connection found\n";
                return;
            }
            DataWriter datawritter = new DataWriter(_streamsocket.OutputStream);

            // cấu trúc dữ liệu gởi đi gồm 
            // [độ dài chuỗi]_[chuỗi]
            // có độ dài chuỗi đễ dễ đọc.   

            // Ghi độ dài chuỗi
            datawritter.WriteUInt32(datawritter.MeasureString(message));

            // Ghi chuỗi
            datawritter.WriteString(message);
            try
            {
                // Gửi Socket đi 
                await datawritter.StoreAsync();

                // Xuất thông tin ra màn hình bằng textbox
                this.textboxDebug.Text += "Send from " + _streamsocket.Information.LocalAddress + ": " + message + "\n";
            }
            catch (Exception ex)
            {
                this.textboxDebug.Text += ex.Message + "\n";
            }
        }
开发者ID:nokia6102,项目名称:StreamSocketExample,代码行数:31,代码来源:MainPage.xaml.cs


注:本文中的Windows.Storage.Streams.DataWriter.WriteUInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。