本文整理汇总了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);
}
}
示例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;
}
}
示例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
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}
示例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));
}
}
示例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)
{
}
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}