C#的SNTP客户端取SNTP时间服务器代码

SNTP C++实现 软件产品的发布中经常会遇到授权期限的问题,常见的做法是保存安装日期、上一次运行时间、运行次数、运行总次数等数据到注册表中,在需要的时候读系统时间做判断。这种做法的缺陷是显而易见的,不必多说。较为安全的做法是使用SNTP协议,获取UTC时间,但这只适用于需要网络环境的软件产品。本文用C++实现了获取标准UTC时间。         参考资料: http://www.codeproject 阅读详情


代码如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading ;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Net;

 

namespace AutoExitWindows
{
 // Leap indicator field values
 public enum _LeapIndicator
 {
  NoWarning,  // 0 - No warning
  LastMinute61, // 1 - Last minute has 61 seconds
  LastMinute59, // 2 - Last minute has 59 seconds
  Alarm   // 3 - Alarm condition (clock not synchronized)
 }

 //Mode field values
 public enum _Mode
 {
  SymmetricActive, // 1 - Symmetric active
  SymmetricPassive, // 2 - Symmetric pasive
  Client,    // 3 - Client
  Server,    // 4 - Server
  Broadcast,   // 5 - Broadcast
  Unknown    // 0, 6, 7 - Reserved
 }

 // Stratum field values
 public enum _Stratum
 {
  Unspecified,   // 0 - unspecified or unavailable
  PrimaryReference,  // 1 - primary reference (e.g. radio-clock)
  SecondaryReference,  // 2-15 - secondary reference (via NTP or SNTP)
  Reserved    // 16-255 - reserved
 }

 /// <summary>
 /// SNTPTimeClient 的摘要说明。
 ///
 /// Public class members:
 ///
 /// LeapIndicator - Warns of an impending leap second to be inserted/deleted in the last
 /// minute of the current day. (See the _LeapIndicator enum)
 ///
 /// VersionNumber - Version number of the protocol (3 or 4).
 ///
 /// Mode - Returns mode. (See the _Mode enum)
 ///
 /// Stratum - Stratum of the clock. (See the _Stratum enum)
 ///
 /// PollInterval - Maximum interval between successive messages.
 ///
 /// Precision - Precision of the clock.
 ///
 /// RootDelay - Round trip time to the primary reference source.
 ///
 /// RootDispersion - Nominal error relative to the primary reference source.
 ///
 /// ReferenceID - Reference identifier (either a 4 character string or an IP address).
 ///
 /// ReferenceTimestamp - The time at which the clock was last set or corrected.
 ///
 /// OriginateTimestamp - The time at which the request departed the client for the server.
 ///
 /// ReceiveTimestamp - The time at which the request arrived at the server.
 ///
 /// Transmit Timestamp - The time at which the reply departed the server for client.
 ///
 /// RoundTripDelay - The time between the departure of request and arrival of reply.
 ///
 /// LocalClockOffset - The offset of the local clock relative to the primary reference
 /// source.
 ///
 /// Initialize - Sets up data structure and prepares for connection.
 ///
 /// Connect - Connects to the time server and populates the data structure.
 ///
 /// IsResponseValid - Returns true if received data is valid and if comes from
 /// a NTP-compliant time server.
 ///
 /// ToString - Returns a string representation of the object.
 ///
 /// -----------------------------------------------------------------------------
 /// Structure of the standard NTP header (as described in RFC 2030)
 ///                       1                   2                   3
 ///   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |LI | VN  |Mode |    Stratum    |     Poll      |   Precision   |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                          Root Delay                           |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                       Root Dispersion                         |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                     Reference Identifier                      |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                                                               |
 ///  |                   Reference Timestamp (64)                    |
 ///  |                                                               |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                                                               |
 ///  |                   Originate Timestamp (64)                    |
 ///  |                                                               |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                                                               |
 ///  |                    Receive Timestamp (64)                     |
 ///  |                                                               |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                                                               |
 ///  |                    Transmit Timestamp (64)                    |
 ///  |                                                               |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                 Key Identifier (optional) (32)                |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///  |                                                               |
 ///  |                                                               |
 ///  |                 Message Digest (optional) (128)               |
 ///  |                                                               |
 ///  |                                                               |
 ///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///
 /// -----------------------------------------------------------------------------
 ///
 /// NTP Timestamp Format (as described in RFC 2030)
 ///                         1                   2                   3
 ///     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 /// |                           Seconds                             |
 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 /// |                  Seconds Fraction (0-padded)                  |
 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 ///
 /// </summary>
 public class SNTPTimeClient
 {
  // NTP Data Structure Length
  private const byte NTPDataLength = 48;
  // NTP Data Structure (as described in RFC 2030)
  byte []NTPData = new byte[NTPDataLength];

  // Offset constants for timestamps in the data structure
  private const byte offReferenceID   = 12;
  private const byte offReferenceTimestamp = 16;
  private const byte offOriginateTimestamp = 24;
  private const byte offReceiveTimestamp   = 32;
  private const byte offTransmitTimestamp  = 40;

  // Leap Indicator
  public _LeapIndicator LeapIndicator
  {
   get
   {
    // Isolate the two most significant bits
    byte val = (byte)(NTPData[0] >> 6);
    switch(val)
    {
     case 0: return _LeapIndicator.NoWarning;
     case 1: return _LeapIndicator.LastMinute61;
     case 2: return _LeapIndicator.LastMinute59;
     case 3:
     default:
      return _LeapIndicator.Alarm;
    }
   }
  }

  // Version Number
  public byte VersionNumber
  {
   get
   {
    // Isolate bits 3 - 5
    byte val = (byte)((NTPData[0] & 0x38) >> 3);
    return val;
   }
  }

  // Mode
  public _Mode Mode
  {
   get
   {
    // Isolate bits 0 - 3
    byte val = (byte)(NTPData[0] & 0x7);
    switch(val)
    {
     case 0:
     case 6:
     case 7:
     default:
      return _Mode.Unknown;
     case 1:
      return _Mode.SymmetricActive;
     case 2:
      return _Mode.SymmetricPassive;
     case 3:
      return _Mode.Client;
     case 4:
      return _Mode.Server;
     case 5:
      return _Mode.Broadcast;
    }
   }
  }

  // Stratum
  public _Stratum Stratum
  {
   get
   {
    byte val = (byte)NTPData[1];
    if(val == 0) return _Stratum.Unspecified;
    else
     if(val == 1) return _Stratum.PrimaryReference;
    else
     if(val <= 15) return _Stratum.SecondaryReference;
    else
     return _Stratum.Reserved;
   }
  }

  // Poll Interval
  public uint PollInterval
  {
   get
   {
    return (uint)Math.Round(Math.Pow(2, NTPData[2]));
   }
  }

  // Precision (in milliseconds)
  public double Precision
  {
   get
   {
    return (1000 * Math.Pow(2, NTPData[3]));
   }
  }

  // Root Delay (in milliseconds)
  public double RootDelay
  {
   get
   {
    int temp = 0;
    temp = 256 * (256 * (256 * NTPData[4] + NTPData[5]) + NTPData[6]) + NTPData[7];
    return 1000 * (((double)temp) / 0x10000);
   }
  }

  // Root Dispersion (in milliseconds)
  public double RootDispersion
  {
   get
   {
    int temp = 0;
    temp = 256 * (256 * (256 * NTPData[8] + NTPData[9]) + NTPData[10]) + NTPData[11];
    return 1000 * (((double)temp) / 0x10000);
   }
  }

  // Reference Identifier
  public string ReferenceID
  {
   get
   {
    string val = "";
    switch(Stratum)
    {
     case _Stratum.Unspecified:
     case _Stratum.PrimaryReference:
      val += Convert.ToChar(NTPData[offReferenceID + 0]);
      val += Convert.ToChar(NTPData[offReferenceID + 1]);
      val += Convert.ToChar(NTPData[offReferenceID + 2]);
      val += Convert.ToChar(NTPData[offReferenceID + 3]);
      break;
     case _Stratum.SecondaryReference:
      ////     switch(VersionNumber)
      ////     {
      ////      case 3: // Version 3, Reference ID is an IPv4 address
      ////       string Address = NTPData[offReferenceID + 0].ToString() + "." +
      ////        NTPData[offReferenceID + 1].ToString() + "." +
      ////        NTPData[offReferenceID + 2].ToString() + "." +
      ////        NTPData[offReferenceID + 3].ToString();
      ////       try
      ////       {
      ////        IPAddress RefAddr = new IPAddress(Address);
      ////        IPHostEntry Host = DNS.GetHostByAddr(RefAddr);
      ////        val = Host.Hostname + " (" + Address + ")";
      ////       }
      ////       catch(Exception)
      ////       {
      ////        val = "N/A";
      ////       }
      ////     
      ////       break;
      ////      case 4: // Version 4, Reference ID is the timestamp of last update
      ////       DateTime time = ComputeDate(GetMilliSeconds(offReferenceID));
      ////       // Take care of the time zone
      ////       long offset = TimeZone.CurrentTimeZone.GetUTCOffset(DateTime.Now);
      ////       TimeSpan offspan = TimeSpan.FromTicks(offset);
      ////       val = (time + offspan).ToString();
      ////       break;
      ////      default:
      ////       val = "N/A";
      ////     }
      break;
    }

    return val;
   }
  }

  // Reference Timestamp
  public DateTime ReferenceTimestamp
  {
   get
   {
    DateTime time = ComputeDate(GetMilliSeconds(offReferenceTimestamp));
    // Take care of the time zone
    long offset = Convert.ToInt64 (TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now));
    TimeSpan offspan = TimeSpan.FromTicks(offset);
    return time + offspan;
   }
  }

  // Originate Timestamp
  public DateTime OriginateTimestamp
  {
   get
   {
    return ComputeDate(GetMilliSeconds(offOriginateTimestamp));
   }
  }

  // Receive Timestamp
  public DateTime ReceiveTimestamp
  {
   get
   {
    DateTime time = ComputeDate(GetMilliSeconds(offReceiveTimestamp));
    // Take care of the time zone
    long offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks;
    TimeSpan offspan = TimeSpan.FromTicks(offset);
    return time + offspan;
   }
  }

  // Transmit Timestamp
  public DateTime TransmitTimestamp
  {
   get
   {
    DateTime time = ComputeDate(GetMilliSeconds(offTransmitTimestamp));
    // Take care of the time zone    
    long offset =  TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks;
    TimeSpan offspan = TimeSpan.FromTicks(offset);
    return time + offspan;
   }
   set
   {
    SetDate(offTransmitTimestamp, value);
   }
  }

  // Reception Timestamp
  public DateTime ReceptionTimestamp;
  
  // Round trip delay (in milliseconds)
  public int RoundTripDelay
  {
   get
   {
    TimeSpan span = (ReceiveTimestamp - OriginateTimestamp) + (ReceptionTimestamp - TransmitTimestamp);
    return (int)span.TotalMilliseconds;
   }
  }

  // Local clock offset (in milliseconds)
  public int LocalClockOffset
  {
   get
   {
    TimeSpan span = (ReceiveTimestamp - OriginateTimestamp) - (ReceptionTimestamp - TransmitTimestamp);
    return (int)(span.TotalMilliseconds / 2);
   }
  }

  // Compute date, given the number of milliseconds since January 1, 1900
  private DateTime ComputeDate(ulong milliseconds)
  {
   TimeSpan span = TimeSpan.FromMilliseconds((double)milliseconds);
   DateTime time = new DateTime(1900, 1, 1);
   time += span;
   return time;
  }

  // Compute the number of milliseconds, given the offset of a 8-byte array
  private ulong GetMilliSeconds(byte offset)
  {
   ulong intpart = 0, fractpart = 0;

   for(int i = 0; i <= 3; i++)
   {
    intpart = 256 * intpart + NTPData[offset + i]; 
   }
   for(int i = 4; i<=7; i++)
   {
    fractpart = 256 * fractpart + NTPData[offset + i];
   }
   ulong milliseconds = intpart * 1000 + (fractpart * 1000) / 0x100000000L;
   return milliseconds;
  }

  // Compute the 8-byte array, given the date
  private void SetDate(byte offset, DateTime date)
  {
   ulong intpart = 0, fractpart = 0;
   DateTime StartOfCentury = new DateTime(1900, 1, 1, 0, 0, 0); // January 1, 1900 12:00 AM

   ulong milliseconds = (ulong)(date - StartOfCentury).TotalMilliseconds;
   intpart = milliseconds / 1000;
   fractpart=((milliseconds % 1000) * 0x100000000L) / 1000;

   ulong temp = intpart;
   for(int i = 3; i >= 0; i--)
   {
    NTPData[offset + i] = (byte) (temp % 256);
    temp = temp / 256;
   }

   temp = fractpart;
   for(int i = 7; i >=4; i--)
   {
    NTPData[offset + i] = (byte) (temp % 256);
    temp = temp / 256;
   }
  }

  // Initialize the NTPClient data
  private void Initialize()
  {
   // Set version number to 4 and Mode to 3 (client)
   NTPData[0] = 0x1B;
   // Initialize all other fields with 0
   for(int i = 1; i < 48; i++)
   {
    NTPData[i] = 0;
   }
   // Initialize the transmit timestamp
   TransmitTimestamp = DateTime.Now;
  }

  // Connect to the time server
  public void Connect()
  {
   try
   {
    IPAddress hostadd = IPAddress.Parse(TimeServer);
    IPEndPoint EPhost = new IPEndPoint(hostadd, Convert.ToInt32(TimePort));

    UdpClient TimeSocket = new UdpClient();     
    TimeSocket.Connect(EPhost);
    Initialize();
    TimeSocket.Send(NTPData, NTPData.Length);
    NTPData = TimeSocket.Receive(ref EPhost);
    if(!IsResponseValid())
    {
     throw new Exception("Invalid response from " + TimeServer);
    }
    ReceptionTimestamp = DateTime.Now;
   }
   catch(SocketException e)
   {
    throw new Exception(e.Message);
   }
  }

  // Check if the response from server is valid
  public bool IsResponseValid()
  {
   if(NTPData.Length < NTPDataLength || Mode != _Mode.Server)
   {
    return false;
   }
   else
   {
    return true;
   }
  }

  // Converts the object to string
  public override string ToString()
  {
   string str;

   str = "Leap Indicator: ";
   switch(LeapIndicator)
   {
    case _LeapIndicator.NoWarning:
     str += "No warning";
     break;
    case _LeapIndicator.LastMinute61:
     str += "Last minute has 61 seconds";
     break;
    case _LeapIndicator.LastMinute59:
     str += "Last minute has 59 seconds";
     break;
    case _LeapIndicator.Alarm:
     str += "Alarm Condition (clock not synchronized)";
     break;
   }
   str += "/r/nVersion number: " + VersionNumber.ToString() + "/r/n";
   str += "Mode: ";
   switch(Mode)
   {
    case _Mode.Unknown:
     str += "Unknown";
     break;
    case _Mode.SymmetricActive:
     str += "Symmetric Active";
     break;
    case _Mode.SymmetricPassive:
     str += "Symmetric Pasive";
     break;
    case _Mode.Client:
     str += "Client";
     break;
    case _Mode.Server:
     str += "Server";
     break;
    case _Mode.Broadcast:
     str += "Broadcast";
     break;
   }
   str += "/r/nStratum: ";
   switch(Stratum)
   {
    case _Stratum.Unspecified:
    case _Stratum.Reserved:
     str += "Unspecified";
     break;
    case _Stratum.PrimaryReference:
     str += "Primary Reference";
     break;
    case _Stratum.SecondaryReference:
     str += "Secondary Reference";
     break;
   }
   str += "/r/nLocal time: " + TransmitTimestamp.ToString();
   str += "/r/nPrecision: " + Precision.ToString() + " ms";
   str += "/r/nPoll Interval: " + PollInterval.ToString() + " s";
   str += "/r/nReference ID: " + ReferenceID.ToString();
   str += "/r/nRoot Dispersion: " + RootDispersion.ToString() + " ms";
   str += "/r/nRound Trip Delay: " + RoundTripDelay.ToString() + " ms";
   str += "/r/nLocal Clock Offset: " + LocalClockOffset.ToString() + " ms";
   str += "/r/n";

   return str;
  }

  // The URL of the time server we're connecting to
  private string TimeServer;
  private string TimePort;

  public SNTPTimeClient(string host, string port)
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
   TimeServer = host;
   TimePort=port;
  }

 }
}


调用时

SNTPTimeClient client=new SNTPTimeClient(Server,Port);
    client.Connect();    
    string strTest=client.ToString();
    Console.Write(strTest);

用C#(.NET8)开发一个NTP(SNTP)服务 C# 开发的一个 NTP 时间服务,代码精简,测试通过 阅读详情

相关推荐

C#实现SNTP协议(附完整源码)

C#实现SNTP协议(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 265

内网电脑服务器时间修改,局域网内,用C#实现本地电脑获取服务器系统时间,并更新到本地电脑...

//从本机获取服务器时间SNTPTimeClient client = new SNTPTimeClient("10.0.5.126", "123");///////填写你想要的获取时间的主机的IP和端口;client.Connect();DateTime getEd = client.ReceiveTimestamp;//获取指定IP的系统时间SystemTime st = new System...

weixin_39655160的博客 1035

C#实现NTP时钟同步:获取并同步指定IP时间

网络时间协议(Network Time Protocol,NTP)是网络基础架构的核心组成部分之一。在数据传输、日志记录、事件序列化、分布式计算和许多其他IT操作中,时间的准确性和一致性至关重要。NTP协议通过网络同步不同计算机的时间信息,使得即使在分布式系统中,不同设备之间的时间也能够保持高度一致。NTP的工作原理基于客户端-服务器模式,允许计算机通过互联网查询时间服务器来获取准确的时间。NTP协议自1985年首次发布以来,已经经过了多次版本升级和改进,目前广泛使用的版本是NTPv4。

weixin_35749796的博客 1722

用网页来实现修改服务器系统时间

用网页来实现修改服务器系统时间 由于自动化测试需要,经常要修改内部web服务器的系统时间 先上代码 using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; namespace HQ.Job

胡杰的专栏 1万+

Windows系统时间同步机制与JInternetTimer应用详解

你看,一个小小的时间同步,牵动着硬件、操作系统、网络协议、安全机制、应用逻辑……方方面面。它不像CPU或内存那样直观,却在关键时刻决定生死。无论是W32Time的稳健保守,还是JInternetTimer的灵活补位,亦或是NTP协议背后的精巧数学,都在告诉我们一件事:精准的时间,从来都不是理所当然的。所以,下次当你看到“时间已成功同步”时,不妨多想一秒——这背后,是多少工程师的智慧结晶啊!✨本文还有配套的精品资源,点击获取。

weixin_42524864的博客 1117

c# ntp时间 客户端

用法 SNTPTimeClient client = new SNTPTimeClient(“127.0.1.1”, "123"); client.Connect(); DateTime getEd = client.ReceiveTimestamp; SystemTime st=new SystemTime(); st.wDay=(ushort)getEd.Day; st.wDayOfWeek = (ushort)getEd.DayOfWeek; st.wHour = (ushort)getEd.Hour; st.wMiliseconds = (ushort)getEd.Millisecond; st.wMinute = (ushort)getEd.Minute; st.wMonth = (ushort)getEd.Month; st.wSecond = (ushort)getEd.Second; st.wYear = (ushort)getEd.Year; SNTPTimeClient.SetLocalTime(ref st); ntp服务器windows版下载http://www.meinberg.de/english/sw/ntp.htm

C#获取Internet服务器的时间

usingSystem;usingSystem.Net;usingSystem.Net.Sockets;namespaceSNTPTime{//Leapindicatorfieldvaluespublicenum_LeapIndicator{NoWarning,//0-NowarningLastMin...

abc11111118的博客 359

SNTPCLient

SNTP客户端服务器模式下的客户端程序,是源码。我在网上下的,希望对想学SNTP校时的人有帮助。

实现sntp协议从网络时间服务器获取时间信息

发出时间A、接收时间B、回复时间C、收到回复时间D、报文从客户端到服务器传输时长L,客户端与服务器偏差时间值X,公式1:A+X+L=B,公式2:C-X+L=D,从公式1得出L=B-A-X,那么公式2可以是C-X+B-A-X=D,推导出2X=C-A+B-D=C-A+(B-D),偏差时间值X= ((C-A)+(B-D)) / 2

lzl_li的专栏 1132

ElasticSearch集群搭建

docker安装es集群

weixin_46562226的博客 2025

VS2022+Qt6保姆级环境配置指南:从插件安装到项目互通全流程

本文提供VS2022与Qt6深度整合的全流程指南,涵盖环境配置、插件安装、项目互通等关键步骤。详细解析编译器版本匹配、跨IDE协作方案及效能优化技巧,帮助开发者高效搭建C++界面设计开发环境,实现软件项目无缝互通。

zero1的博客 733

CNTP时钟同步获取指定IP系统时间:轻松实现时间同步

CNTP时钟同步获取指定IP系统时间:轻松实现时间同步 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在当今的信息化时代,时间同步对于系统运行和数据一致性至关重要。C# NTP 时钟同步获取指定IP系统时间项目(简称CNTP),为开发者和系统管理员提供了一种简便、高效的方法,实现本地时间与远程服务器时间的同步。通过采用SNTP协议,CNTP能够精准地获取指定IP地址的...

gitblog_06728的博客 676

手把手教你用GNU Radio和PlutoSDR搭建FM收音机(附完整流程图)

本文提供了一份详细的实践指南,教你如何使用GNU Radio和PlutoSDR搭建一个功能完整的FM收音机。从软硬件环境准备、核心流程图构建,到运行调试与效果优化,手把手带你完成从射频信号接收、下变频、FM解调到音频输出的全过程,是入门软件定义无线电(SDR)的绝佳实践项目。

weixin_29189377的博客 750

(转)C#获取Internet服务器的时间

using System;using System.Net;using System.Net.Sockets;namespace SNTPTime{    // Leap indicator field values    public enum _LeapIndicator    {        NoWarning,  // 0 - No warning        LastMinute61

寒风雨(lanman)的专栏 3625

PAM4信号测试实战:从眼图分析到误码率测量的技术演进

在高速数字系统设计中,信号完整性测试是确保数据传输可靠性的核心环节。其基本原理在于通过时域和频域分析,精确评估信号在传输过程中的质量衰减与失真。随着数据速率向56Gbps及以上演进,传统的NRZ编码面临带宽瓶颈,而PAM4调制技术通过在每个符号周期内承载更多比特信息,成为提升信道效率的关键路径。这项技术的工程价值在于,它允许在相同带宽下实现翻倍的数据吞吐量,这对于数据中心互联、PCIe 6.0及800G以太网等高速接口至关重要。然而,PAM4信号电平间距更小,对噪声和抖动极为敏感,导致其原始误码率显著升高,

weixin_42522817的博客 657

Flutter 中使用蓝牙插件报错,说没有权限怎么解决

2、在build.grale里面更改一下版本号,我修改的是targetSdkVersion这个版本号,需要根据你自己的版本进行更改,记得更改之后先flutter clean一下再run。搞了一晚上,没搞出来,第二天用同事手机测试发现他手机可以,我手机还是不行,才发现是Android版本问题,需要修改两处地方。废话不多说,咱先看报错信息。

zzj17637822814的博客 2289

RP2040有线网络授时方案:基于W5500 HAT与SNTP协议的精准时间同步实践

在嵌入式系统开发中,精准的时间同步是数据采集、事件记录和设备协同的基础需求。其核心原理是通过网络时间协议(NTP)或简化版(SNTP)从时间服务器获取标准时间,以校准设备本地时钟。这项技术对于物联网节点、工业控制器等场景具有重要价值,能确保数据时间戳的准确性和系统行为的时序一致性。本文聚焦于资源受限的微控制器(MCU)场景,探讨如何利用硬件协议栈芯片分担网络处理负载,实现稳定可靠的有线网络授时。具体地,通过整合RP2040微控制器与内置硬件TCP/IP协议栈的W5500以太网芯片,构建了一个高效、低负载的S

weixin_33785108的博客 378

pi-coding-agent 完整详解

pi-coding-agent是一个由Mario Zechner开发的专业AI编程助手,基于Node.js和TypeScript构建。核心功能包括:1)多级思考模式(ThinkingLevel),从none到ultra控制推理深度;2)对话压缩(compaction)管理长对话记忆;3)WebSocket实时通信支持流式交互。该智能体支持代码生成、调试、重构等专业编程任务,采用AI Agent架构,具备工具调用和多轮记忆能力。项目结构通常包含server、agent、config等模块,可通过二次开发扩展功

大坡3D软件开发 2423

C#远程时间同步助手软件设计

C#远程时间同步助手软件设计 原文:C#远程时间同步助手软件设计C#远程时间同步助手软件设计 本程序才C#语言开发,实现远程时间同步功能,可以将本地时间每隔一段时间与时间服务器时间进行同步!不足之处还望见谅! 软件开发环境:Visual Studio 2010 软件安装简单说明 时间服务器的ntp服务开启状态: TimeSyn...

weixin_30809333的博客 267

通信算法之264: DJI O2 协议物理层逆向工程解析

对于 DroneID,标志之间的间隙由循环前缀 (CP) 填充:每个标志末尾的副本附加在相应标志的开头。有了关于确切标志开始的信息,可以使用 FFT 将标志转移到频域 - 来自时域的 1024 个样本导致频域中的 1024 个子载波。使用比特流的解扰和涡轮解码,并将生成的数据映射到如上的DroneID 结构,通过逆向工程在无人机的固件中找到了它。注意到一些无人机(Mavic 2 和更早的 OcuSync 无人机)不发送第一个标志(标志 1),这导致更短的帧持续时间为 576 µs。//产品型号数字代号。

leegang12的专栏 3946

关于React Native Android找不到node的错误

最近,按照官方文档初始化了一个React Native项目,但是在Android端运行的时候,报了如下的一个错误。 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:recordFilesBeforeBundleCommandDebug'. Caused by: org.gradle.process.internal.ExecException: A problem occurred starting p

xiangzhihong8的专栏 4246

ntp原理及客户端实现

ntp原理及客户端实现NTP简介NTP(Network Time Protocol)是由美国德拉瓦大学的David L. Mills教授于1985年提出,除了可以估算封包在网络上的往返延迟外,还可独立地估算计算机时钟偏差,从而实现在网络上的高精准度计算机校时,它是设计用来在Internet上使不同的机器能维持相同时间的一种通信协议。时间服务器(time server)是利用NTP的一种服务

DiegoTJ的专栏 7059

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

跨平台全网计算机时间同步

保持生产环境中全网计算机时间的同步是一件很重要且必须的事情,至少在我们的网络环境中就是这样。我们的网络由一个域和一个工作组组成,域主要是财务系统,而工作组是另一个管理系统,它们都要求计算机时间的一致性,大家都知道,在一个域中计算机时间都是自动同步的,但工作组却没那么简单。 经过讨论,我们最后一致认为全网的计算机时间应该以工作组中的UNIX/MIS服务器为准,于是整个网络的时间同步要求就应该如图1...

weixin_34221773的博客 107

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

C# NTP 时钟同步,获取指定IP地址的系统时间及错误问题解决。

为了实现内网间机子的时钟同步,需要用到NTP协议的,所以做了一下这方面工作。 实现获取指定IP系统时间的代码在网上有现成的: 这里有一个网友提供的免费下载的地址:http://wenku.baidu.com/view/07d8aad53186bceb19e8bb25.html 调用的方法如下: var client = new SNTPTimeClient("127.0.0

wushang923的专栏 1万+

通过NTP协议进行时间同步

最近发现手机的时间不是很准了,便到网上下了一个同步时间的小程序,简单了看了一下它的原理,是通过NTP协议来实现校时的,就顺便学习了一下NTP协议,用C#写了个简单的实现。 NTP(Network Time Protocol,网络时间协议)是由RFC 1305定义的时间同步协议,用来在分布式时间服务器和客户端之间进行时间同步。 NTP工作原理 NTP的基本工作原理如下图所示。Devi...

weixin_30604651的博客 127
上一篇: C#写的Win2000关机代码
下一篇: C#从网络获取时间更新本机时间
limit
博客等级 码龄25年 1粉丝 13原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值