本文整理汇总了C#中Windows.GetDataReader方法的典型用法代码示例。如果您正苦于以下问题:C# Windows.GetDataReader方法的具体用法?C# Windows.GetDataReader怎么用?C# Windows.GetDataReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows
的用法示例。
在下文中一共展示了Windows.GetDataReader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Socket_MessageReceived
private void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
uint dataLength = args.GetDataReader().UnconsumedBufferLength;
byte[] result = new byte[dataLength];
args.GetDataReader().ReadBytes(result);
SupportClass.PacketSupport packet = new SupportClass.PacketSupport(result, result.Length, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(args.RemoteAddress.CanonicalName), int.Parse(args.RemotePort)));
try
{
if (Enclosing_Instance.localHost.ShouldIgnorePacket(packet))
return;
DNSIncoming msg = new DNSIncoming(packet);
logger.Debug("SocketListener.run() JmDNS in:" + msg.Print(true));
lock (Enclosing_Instance.IOLock)
{
if (msg.Query)
{
if (packet.Port != DNSConstants.MDNS_PORT)
{
Enclosing_Instance.HandleQuery(msg, packet.Address, packet.Port);
}
Enclosing_Instance.HandleQuery(msg, Enclosing_Instance.Group, DNSConstants.MDNS_PORT);
}
else
{
Enclosing_Instance.HandleResponse(msg);
}
}
}
catch (IOException e)
{
logger.Warn("run() exception ", e);
}
}
示例2: Socket_Completed_Receive
private void Socket_Completed_Receive(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
try
{
ExecuteWithSuppressedExceptions(() => sender.MessageReceived -= this.Socket_Completed_Receive);
byte[] buffer = null;
using (var reader = args.GetDataReader())
{
buffer = new byte[reader.UnconsumedBufferLength];
reader.ReadBytes(buffer);
}
ConvertBufferToCurrentTime(buffer);
}
catch (Exception ex)
{
OnErrorOccurred(ExceptionToNtpNetworkException(ex));
}
}
示例3: _Socket_MessageReceived
private void _Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
using (var reader = args.GetDataReader())
{
var data = new ReceivedUdpData()
{
ReceivedBytes = Convert.ToInt32(reader.UnconsumedBufferLength),
ReceivedFrom = new UdpEndPoint()
{
IPAddress = args.RemoteAddress.RawName,
Port = Convert.ToInt32(args.RemotePort)
}
};
data.Buffer = new byte[data.ReceivedBytes];
reader.ReadBytes(data.Buffer);
_ReceivedData.Enqueue(data);
_DataAvailableSignal.Set();
}
}
示例4: OnNTPTimeReceived
/// <summary>
/// Event hander when receiving response from the ntp server.
/// </summary>
/// <param name="socket">The udp socket object which triggered this event </param>
/// <param name="eventArguments">event information</param>
void OnNTPTimeReceived(Windows.Networking.Sockets.DatagramSocket socket, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs eventArguments)
{
int currentRTT = (int)ntpResponseMonitor.ElapsedMilliseconds;
Debug.WriteLine($"NtpSync: current RTT {currentRTT}");
ntpResponseMonitor.Stop();
if (currentNtpQueryCount < MaxNtpRTTProbeQuery)
{
//we only trace 'min' RTT within the RTT probe attempts
if (minNtpRTT == -1 || minNtpRTT > currentRTT)
{
minNtpRTT = currentRTT;
if (minNtpRTT == 0)
minNtpRTT = 1; //in case we got response so fast, consider it to be 1ms.
}
averageNtpRTT = (averageNtpRTT * (currentNtpQueryCount - 1) + currentRTT) / currentNtpQueryCount;
if (averageNtpRTT < 1)
{
averageNtpRTT = 1;
}
RunOnUiThread(() =>
{
ntpQueryTimer.Stop();
ntpRTTIntervalTimer.Start();
});
return;
}
//if currentRTT is good enough, e.g.: closer to minRTT, then, we don't have to continue to query.
if (currentRTT > (averageNtpRTT + minNtpRTT) / 2)
{
RunOnUiThread(() =>
{
ntpQueryTimer.Stop();
ntpRTTIntervalTimer.Start();
});
return;
}
byte[] ntpData = new byte[48];
eventArguments.GetDataReader().ReadBytes(ntpData);
//Offset to get to the "Transmit Timestamp" field (time at which the reply
//departed the server for the client, in 64-bit timestamp format."
const byte serverReplyTime = 40;
//Get the seconds part
ulong intPart = BitConverter.ToUInt32(ntpData, serverReplyTime);
//Get the seconds fraction
ulong fractPart = BitConverter.ToUInt32(ntpData, serverReplyTime + 4);
//Convert From big-endian to little-endian
intPart = SwapEndianness(intPart);
fractPart = SwapEndianness(fractPart);
ulong milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L);
RunOnUiThread(() =>
{
OnNTPTimeAvailable?.Invoke((long)milliseconds + currentRTT / 2);
});
socket.Dispose();
ReportNtpSyncStatus(true, currentRTT);
}
示例5: UdpSocket_MessageReceived
private void UdpSocket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
try
{
Windows.Storage.Streams.DataReader dr = args.GetDataReader();
dr.InputStreamOptions = Windows.Storage.Streams.InputStreamOptions.Partial;
uint uLength = dr.UnconsumedBufferLength;
string sCmd = dr.ReadString(uLength);
DataModel.BaseCommand XCmd = DataModel.XCommandFactory.GetInstance().CreateCommand(sCmd);
if (XCmd.CommandType == DataModel.XPCommandType.TYPE_XGPS)
{
CurrentStat.GPSStatus = (DataModel.XCommand_GPS)XCmd;
}
if (XCmd.CommandType == DataModel.XPCommandType.TYPE_XATT)
{
CurrentStat.ATTStatus = (DataModel.XCommand_ATT)XCmd;
}
System.Diagnostics.Debug.WriteLine("Received Message:" + sCmd);
}
catch(Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.ToString());
}
}