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


C# DataReader.ReadUInt32方法代码示例

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


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

示例1: Read

        private async void Read()
        {
            _reader = new DataReader(_socket.InputStream);
            try
            {
                while (true)
                {
                    uint sizeFieldCount = await _reader.LoadAsync(sizeof(uint));
                    //if desconneted
                    if (sizeFieldCount != sizeof(uint))
                        return;

                    uint stringLenght = _reader.ReadUInt32();
                    uint actualStringLength = await _reader.LoadAsync(stringLenght);
                    //if desconneted
                    if (stringLenght != actualStringLength)
                        return;
                    if (OnDataRecived != null)
                        OnDataRecived(_reader.ReadString(actualStringLength));
                }

            }
            catch (Exception ex)
            {
                if (OnError != null)
                    OnError(ex.Message);
            }
        }
开发者ID:lillo42,项目名称:IoT,代码行数:28,代码来源:SocketClient.cs

示例2: OnRead

        private async void OnRead(Object sender, RoutedEventArgs e)
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;

            StorageFile file = await local.GetFileAsync("demo.dat");
            if(file != null)
            {
                string strres = "读到的内容:\n";
                using(IRandomAccessStream stream = await file.OpenReadAsync())
                {
                    DataReader dr = new DataReader(stream);
                    dr.UnicodeEncoding = UnicodeEncoding.Utf8;
                    await dr.LoadAsync((uint)stream.Size);
                    bool b = dr.ReadBoolean();
                    strres += b.ToString() + "\n";
                    DateTimeOffset dt = dr.ReadDateTime();
                    strres += dt.ToString("yyyy-M-d") + "\n";
                    uint len = dr.ReadUInt32();
                    if(len > 0)
                    {
                        strres += dr.ReadString(len);
                    }
                    dr.Dispose();
                }
                tbResult.Text = strres;
            }
        }
开发者ID:forehalo,项目名称:UWP-dev,代码行数:27,代码来源:_DataWriter.xaml.cs

示例3: OnConnection

        private static async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            ConnectionStatus = ConnectionStatus.Connected;
            DataReader reader = new DataReader(args.Socket.InputStream);
            try
            {
                while (true)
                {
                    uint sizeFieldCount = await reader.LoadAsync(sizeof (uint));
                    if (sizeFieldCount != sizeof (uint))
                    {
                        return;
                    }
                    
                    uint stringLength = reader.ReadUInt32();
                    uint actualStringLength = await reader.LoadAsync(stringLength);
                    if (stringLength != actualStringLength)
                    {
                        return;
                    }

                    Message = reader.ReadString(actualStringLength);
                }
            }
            catch (Exception e)
            {
                ConnectionStatus = ConnectionStatus.Failed;
                //TODO:send a connection status message with error
            }
        }
开发者ID:95strat,项目名称:GoPiGoWin10,代码行数:30,代码来源:SocketConnection.cs

示例4: LoadFrom

		public static async Task<bool> LoadFrom ( ObservableCollection<RecentData> datas )
		{
			try
			{
				StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync ( "data.dat" );
				FileRandomAccessStream stream = await sf.OpenAsync ( FileAccessMode.Read ) as FileRandomAccessStream;
				DataReader dr = new DataReader ( stream );
				dr.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
				dr.ByteOrder = ByteOrder.LittleEndian;

				await dr.LoadAsync ( ( uint ) stream.Size );

				int len = dr.ReadInt32 ();
				for ( int i = 0; i < len; i++ )
				{
					RecentData data = new RecentData ();
					uint srclen = dr.ReadUInt32 ();
					data.Source = dr.ReadString ( srclen );
					data.SourceIndex = dr.ReadInt32 ();
					data.TargetIndex = dr.ReadInt32 ();
					datas.Add ( data );
				}

				stream.Dispose ();
			}
			catch { return false; }
			return true;
		}
开发者ID:Daramkun,项目名称:LangTrans,代码行数:28,代码来源:DataManager.cs

示例5: StreamSkeleton

		private async void StreamSkeleton()
		{
			try
			{
                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
					BinaryReader br = new BinaryReader(ms);

					SkeletonFrameData frame = br.ReadSkeletonFrame();

					SkeletonFrameReadyEventArgs args = new SkeletonFrameReadyEventArgs { SkeletonFrame = frame };
					SkeletonFrame = frame;

					Context.Send(delegate
					{
						if(SkeletonFrameReady != null)
							SkeletonFrameReady(this, args);
					}, null);
				}
			}
			catch(IOException)
			{
                Disconnect();
			}
		}
开发者ID:kaorun55,项目名称:KinectService,代码行数:35,代码来源:SkeletonClient.cs

示例6: ColorThread

		private async void ColorThread()
		{
			try
			{
                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;
                reader.ByteOrder = ByteOrder.LittleEndian;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
					BinaryReader br = new BinaryReader(ms);

                    ColorFrameReadyEventArgs args = new ColorFrameReadyEventArgs();
                    ColorFrameData cfd = new ColorFrameData();

                    cfd.Format = (ImageFormat)br.ReadInt32();
					cfd.ImageFrame = br.ReadColorImageFrame();

                    MemoryStream msData = new MemoryStream( bytes, (int)ms.Position, (int)(ms.Length - ms.Position) );
                    if (cfd.Format == ImageFormat.Raw)
                    {
                        cfd.RawImage = ms.ToArray();
                    }
                    else
                    {
                        InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
                        DataWriter dw = new DataWriter(ras.GetOutputStreamAt(0));
                        dw.WriteBytes(msData.ToArray());
                        await dw.StoreAsync();   

                        // Set to the image
                        BitmapImage bImg = new BitmapImage();
                        bImg.SetSource(ras);
                        cfd.BitmapImage = bImg;
                    }

					ColorFrame = cfd;
					args.ColorFrame = cfd;

                    if (ColorFrameReady != null)
                    {
                        ColorFrameReady(this, args);
                    }
				}
			}
			catch(IOException)
			{
				Disconnect();
			}
		}
开发者ID:kaorun55,项目名称:KinectService,代码行数:57,代码来源:ColorClient.cs

示例7: Listener_ConnectionReceived

        private async void Listener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            Debug.WriteLine("Connection Received on Port {0}", sender.Information.LocalPort);
            StreamSocket streamSocket = args.Socket;
            if (streamSocket != null)
            {
                DataReader reader = new DataReader(streamSocket.InputStream);
                try
                {
                    // Read first 4 bytes (length of the subsequent string).
                    uint sizeFieldCount = await reader.LoadAsync(sizeof(uint));
                    if (sizeFieldCount != sizeof(uint))
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    // Read the length of the 'packet'.
                    uint length = reader.ReadUInt32();
                    uint actualLength = await reader.LoadAsync(length);
                    if (length != actualLength)
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    string name = reader.ReadString(actualLength);
                    Speaker speaker = new Speaker()
                    {
                        Name = name,
                        Address = streamSocket.Information.RemoteAddress.DisplayName,
                        Status = "Connected",
                        Socket = streamSocket
                    };

                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () =>
                    {
                        Speakers.Add(speaker);
                    });

                    reader.DetachStream();

                    Debug.WriteLine("New speaker added " + name);

                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error in connection received: " + e);
                }
            }
        }
开发者ID:CHS982,项目名称:Coding4Fun,代码行数:52,代码来源:Publisher.cs

示例8: DepthThread

        private async void DepthThread()
        {
            try {
                short[] depthShort = null;

                var reader = new DataReader( Client.InputStream );
                reader.InputStreamOptions = InputStreamOptions.Partial;

                while ( IsConnected ) {
                    await reader.LoadAsync( 4 );
                    var size = reader.ReadUInt32();

                    await reader.LoadAsync( size );
                    byte[] bytes = new byte[size];
                    reader.ReadBytes( bytes );

                    MemoryStream ms = new MemoryStream( bytes );
                    BinaryReader br = new BinaryReader( ms );

                    DepthFrameData dfd = new DepthFrameData();
                    dfd.PlayerIndexBitmask = br.ReadInt32();
                    dfd.PlayerIndexBitmaskWidth = br.ReadInt32();

                    DepthImageFrame frame = br.ReadDepthImageFrame();
                    dfd.ImageFrame = frame;

                    int dataLength = (int)(ms.Length - ms.Position);

                    if ( depthShort == null || depthShort.Length != dataLength / 2 )
                        depthShort = new short[dataLength / 2];

                    Buffer.BlockCopy( bytes, (int)br.BaseStream.Position, depthShort, 0, dataLength );

                    dfd.DepthData = depthShort;

                    DepthFrame = dfd;

                    DepthFrameReadyEventArgs args = new DepthFrameReadyEventArgs();
                    args.DepthFrame = dfd;

                    Context.Send( delegate
                    {
                        if ( DepthFrameReady != null )
                            DepthFrameReady( this, args );
                    }, null );
                }
            }
            catch ( IOException ) {
                Disconnect();
            }
        }
开发者ID:kaorun55,项目名称:KinectService,代码行数:51,代码来源:DepthClient.cs

示例9: OnConnection

        private async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            string id = string.Empty;

            DataReader reader = new DataReader(args.Socket.InputStream);
            try
            {
                while (true)
                {
                    // Read first 4 bytes (length of the subsequent string).
                    uint sizeFieldCount = await reader.LoadAsync(sizeof(uint));
                    if (sizeFieldCount != sizeof(uint))
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    // Read the string.
                    uint stringLength = reader.ReadUInt32();
                    uint actualStringLength = await reader.LoadAsync(stringLength);
                    if (stringLength != actualStringLength)
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    // Display the string on the screen. The event is invoked on a non-UI thread, so we need to marshal the text back to the UI thread.
                    string readedString = reader.ReadString(actualStringLength);
                    

                    string action = readedString.Split(';')[0].Split(':')[1].ToString();
                    id = readedString.Split(';')[1].Split(':')[1].ToString();

                    OnReceivedMessage(new ActionEventArgs(action, id));
                }
            }
            catch (Exception exception)
            {
                OnReceivedMessage(new ActionEventArgs("closed", id));
            }
        }
开发者ID:devedse,项目名称:TurtleTurner2000,代码行数:41,代码来源:StoreAppListener.cs

示例10: 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

示例11: 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

示例12: Listener_ConnectionReceived

        private async void Listener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            var reader = new DataReader(args.Socket.InputStream);
            _writer = new DataWriter(args.Socket.OutputStream);
            try
            {
                while (true)
                {
                    uint sizeFieldCount = await reader.LoadAsync(sizeof(uint));
                    //Caso ocora um desconexão
                    if (sizeFieldCount != sizeof(uint))
                        return;

                    //Tamanho da string
                    uint stringLenght = reader.ReadUInt32();
                    //Ler os dados do InputStream
                    uint actualStringLength = await reader.LoadAsync(stringLenght);
                    //Caso ocora um desconexão
                    if (stringLenght != actualStringLength)
                        return;
                    //Dispara evento de dado recebido
                    if (OnDataRecived != null)
                    {
                        //Le a string com o tamanho passado
                        string data = reader.ReadString(actualStringLength);
                        //Dispara evento de dado recebido
                        OnDataRecived(data);
                    }
                }

            }
            catch (Exception ex)
            {
                // Dispara evento em caso de erro, com a mensagem de erro
                if (OnError != null)
                    OnError(ex.Message);
            }
        }
开发者ID:lillo42,项目名称:IoT,代码行数:38,代码来源:SocketServer.cs

示例13: Receive

        private static async Task<string> Receive(StreamSocket socket)
        {
            string result = null;

            if (socket != null)
                using (var reader = new DataReader(socket.InputStream))
                {
                    reader.InputStreamOptions = InputStreamOptions.Partial;

                    uint sizeFieldLength = await reader.LoadAsync(sizeof(uint));
                    if (sizeFieldLength == sizeof(uint))
                    {
                        uint dataLength = reader.ReadUInt32();
                        uint actualDataLength = await reader.LoadAsync(dataLength);
                        if (dataLength == actualDataLength)
                            result = reader.ReadString(actualDataLength);
                    }

                    reader.DetachStream();
                }

            return result;
        }
开发者ID:KonstantinKolesnik,项目名称:SmartHub,代码行数:23,代码来源:ApiListenerPlugin.cs

示例14: ClientAdded

        /// <summary>
        /// When new client is added
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void ClientAdded(object sender, EventArgs e)
        {
            var socket = ((CustomEventArgs)e).ClientSocket;

            var clientReader = new DataReader(socket.InputStream);
            clientReader.InputStreamOptions = InputStreamOptions.Partial;

            string clientName;

            while (true)
            {
                uint sizeFieldCount = await clientReader.LoadAsync(sizeof(uint));
                if (sizeFieldCount != sizeof(uint))
                {
                    // The underlying socket was closed before we were able to read the whole data.
                    return;
                }
                uint bytesLength = clientReader.ReadUInt32();
                uint actualBytesLength = await clientReader.LoadAsync(bytesLength);
                if (bytesLength != actualBytesLength)
                {
                    // The underlying socket was closed before we were able to read the whole data.
                    return;
                }
                var buffer = new byte[bytesLength];
                clientReader.ReadBytes(buffer);
                clientName = Encoding.Unicode.GetString(buffer);

                var newClient = new ConnectedClient(clientName, socket);
                clients.Add(newClient);
                break;
            }

            OnClientConnected(socket, clientName);

            foreach (var client in clients)
                SendUsersList(client.Connection, client.UserName, clientName, ChatHelper.CONNECTED);

            var state = new ChatHelper.StateObject
            {
                InputStream = socket.InputStream
            };

            var dataReader = new DataReader(socket.InputStream);


            var buff = new byte[dataReader.UnconsumedBufferLength];
            dataReader.ReadBytes(buff);

            //ChatHelper.WriteToEventLog(Log.ClientConnected, EventLogEntryType.Information);
        }
开发者ID:notdef1ned,项目名称:voice-chat-winrt,代码行数:56,代码来源:ChatServer.cs

示例15: PeerFinder_ConnectionRequested

        private async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            try
            {
                await this.textboxDebug.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                    async () =>
                    {
                        this.textboxDebug.Text += "Connection Requested\n";
                        await this.connect(args.PeerInformation);
                        if (_streamsocket != null)
                        {
                            while (true)
                            {
                                // nếu đã tồn tại một thể hiện của lớp DataReader thì đối tượng đó tự động được giải phóng.
                                DataReader datareader = new DataReader(_streamsocket.InputStream);
                                try
                                {
                                    uint size = await datareader.LoadAsync(sizeof(uint));
                                    if (size != sizeof(uint))
                                    {
                                        return;
                                    }
                                    uint lenght = datareader.ReadUInt32();
                                    uint exactlylenght = await datareader.LoadAsync(lenght);
                                    if (lenght != exactlylenght)
                                    {
                                        return;
                                    }
                                    string msg = datareader.ReadString(exactlylenght);
                                    this.textboxDebug.Text += "Receive from " + _streamsocket.Information.RemoteAddress + ": " + msg + "\n";
                                }
                                catch (Exception ex)
                                {
                                    this.textboxDebug.Text += ex.Message + "\n";
                                }
                            }

                        }
                    });
            }
            catch (Exception ex)
            {
                this.textboxDebug.Text += ex.Message + "\n";
            }


            //await PeerFinder.ConnectAsync(args.PeerInformation);
            // throw new NotImplementedException();
        }
开发者ID:nokia6102,项目名称:StreamSocketExample,代码行数:49,代码来源:MainPage.xaml.cs


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