C# NTP时间同步类

添加类 NTPClient

    /// <summary>/// SNTPClient is a C# class designed to connect to time servers on the Internet and/// fetch the current date and time. Optionally, it may update the time of the local system./// The implementation of the protocol is based on the RFC 2030./// /// Public class members:/// /// Initialize - Sets up data structure and prepares for connection./// /// Connect - Connects to the time server and populates the data structure.///    It can also update the system time./// /// 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)               |///  |                                                               |///  |                                                               |///  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+/// /// -----------------------------------------------------------------------------/// /// SNTP 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 NTPClient{/// <summary>/// SNTP Data Structure Length/// </summary>private const byte SNTPDataLength = 48;/// <summary>/// SNTP Data Structure (as described in RFC 2030)/// </summary>byte[] SNTPData = new byte[SNTPDataLength];//Offset constants for timestamps in the data structureprivate const byte offReferenceID = 12;private const byte offReferenceTimestamp = 16;private const byte offOriginateTimestamp = 24;private const byte offReceiveTimestamp = 32;private const byte offTransmitTimestamp = 40;/// <summary>/// Leap Indicator Warns of an impending leap second to be inserted/deleted in the last  minute of the current day. 值为“11”时表示告警状态,时钟未被同步。为其他值时NTP本身不做处理/// </summary>public _LeapIndicator LeapIndicator{get{// Isolate the two most significant bitsbyte val = (byte)(SNTPData[0] >> 6);switch (val){case 0: return _LeapIndicator.NoWarning;case 1: return _LeapIndicator.LastMinute61;case 2: return _LeapIndicator.LastMinute59;case 3: goto default;default:return _LeapIndicator.Alarm;}}}/// <summary>/// Version Number Version number of the protocol (3 or 4) NTP的版本号/// </summary>public byte VersionNumber{get{// Isolate bits 3 - 5byte val = (byte)((SNTPData[0] & 0x38) >> 3);return val;}}/// <summary>/// Mode 长度为3比特,表示NTP的工作模式。不同的值所表示的含义分别是:0未定义、1表示主动对等体模式、2表示被动对等体模式、3表示客户模式、4表示服务器模式、5表示广播模式或组播模式、6表示此报文为NTP控制报文、7预留给内部使用/// </summary>public _Mode Mode{get{// Isolate bits 0 - 3byte val = (byte)(SNTPData[0] & 0x7);switch (val){case 0:return _Mode.Unknown;case 6:return _Mode.Unknown;case 7:return _Mode.Unknown;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;}}}/// <summary>/// Stratum 系统时钟的层数,取值范围为1~16,它定义了时钟的准确度。层数为1的时钟准确度最高,准确度从1到16依次递减,层数为16的时钟处于未同步状态,不能作为参考时钟/// </summary>public _Stratum Stratum{get{byte val = (byte)SNTPData[1];if (val == 0) return _Stratum.Unspecified;elseif (val == 1) return _Stratum.PrimaryReference;elseif (val <= 15) return _Stratum.SecondaryReference;elsereturn _Stratum.Reserved;}}/// <summary>/// Poll Interval (in seconds) Maximum interval between successive messages 轮询时间,即两个连续NTP报文之间的时间间隔/// </summary>public uint PollInterval{get{// Thanks to Jim Hollenhorst <hollenho@attbi.com>return (uint)(Math.Pow(2, (sbyte)SNTPData[2]));}}/// <summary>/// Precision (in seconds) Precision of the clock 系统时钟的精度/// </summary>public double Precision{get{// Thanks to Jim Hollenhorst <hollenho@attbi.com>return (Math.Pow(2, (sbyte)SNTPData[3]));}}/// <summary>/// Root Delay (in milliseconds) Round trip time to the primary reference source NTP服务器到主参考时钟的延迟/// </summary>public double RootDelay{get{int temp = 0;temp = 256 * (256 * (256 * SNTPData[4] + SNTPData[5]) + SNTPData[6]) + SNTPData[7];return 1000 * (((double)temp) / 0x10000);}}/// <summary>/// Root Dispersion (in milliseconds) Nominal error relative to the primary reference source 系统时钟相对于主参考时钟的最大误差/// </summary>public double RootDispersion{get{int temp = 0;temp = 256 * (256 * (256 * SNTPData[8] + SNTPData[9]) + SNTPData[10]) + SNTPData[11];return 1000 * (((double)temp) / 0x10000);}}/// <summary>/// Reference Identifier Reference identifier (either a 4 character string or an IP address)/// </summary>public string ReferenceID{get{string val = "";switch (Stratum){case _Stratum.Unspecified:goto case _Stratum.PrimaryReference;case _Stratum.PrimaryReference:val += (char)SNTPData[offReferenceID + 0];val += (char)SNTPData[offReferenceID + 1];val += (char)SNTPData[offReferenceID + 2];val += (char)SNTPData[offReferenceID + 3];break;case _Stratum.SecondaryReference:switch (VersionNumber){case 3:    // Version 3, Reference ID is an IPv4 addressstring Address = SNTPData[offReferenceID + 0].ToString() + "." +SNTPData[offReferenceID + 1].ToString() + "." +SNTPData[offReferenceID + 2].ToString() + "." +SNTPData[offReferenceID + 3].ToString();try{IPHostEntry Host = Dns.GetHostEntry(Address);val = Host.HostName + " (" + Address + ")";}catch (Exception){val = "N/A";}break;case 4: // Version 4, Reference ID is the timestamp of last updateDateTime time = ComputeDate(GetMilliSeconds(offReferenceID));// Take care of the time zoneTimeSpan offspan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);val = (time + offspan).ToString();break;default:val = "N/A";break;}break;}return val;}}/// <summary>/// Reference Timestamp The time at which the clock was last set or corrected NTP系统时钟最后一次被设定或更新的时间/// </summary>public DateTime ReferenceTimestamp{get{DateTime time = ComputeDate(GetMilliSeconds(offReferenceTimestamp));// Take care of the time zoneTimeSpan offspan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);return time + offspan;}}/// <summary>/// Originate Timestamp (T1)  The time at which the request departed the client for the server. 发送报文时的本机时间/// </summary>public DateTime OriginateTimestamp{get{return ComputeDate(GetMilliSeconds(offOriginateTimestamp));}}/// <summary>/// Receive Timestamp (T2) The time at which the request arrived at the server. 报文到达NTP服务器时的服务器时间/// </summary>public DateTime ReceiveTimestamp{get{DateTime time = ComputeDate(GetMilliSeconds(offReceiveTimestamp));// Take care of the time zoneTimeSpan offspan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);return time + offspan;}}/// <summary>/// Transmit Timestamp (T3) The time at which the reply departed the server for client.  报文从NTP服务器离开时的服务器时间/// </summary>public DateTime TransmitTimestamp{get{DateTime time = ComputeDate(GetMilliSeconds(offTransmitTimestamp));// Take care of the time zoneTimeSpan offspan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);return time + offspan;}set{SetDate(offTransmitTimestamp, value);}}/// <summary>/// Destination Timestamp (T4) The time at which the reply arrived at the client. 接收到来自NTP服务器返回报文时的本机时间/// </summary>public DateTime DestinationTimestamp;/// <summary>/// Round trip delay (in milliseconds) The time between the departure of request and arrival of reply 报文从本地到NTP服务器的往返时间/// </summary>public double RoundTripDelay{get{// Thanks to DNH <dnharris@csrlink.net>TimeSpan span = (DestinationTimestamp - OriginateTimestamp) - (ReceiveTimestamp - TransmitTimestamp);return span.TotalMilliseconds;}}/// <summary>/// Local clock offset (in milliseconds)  The offset of the local clock relative to the primary reference source.本机相对于NTP服务器(主时钟)的时间差/// </summary>public double LocalClockOffset{get{// Thanks to DNH <dnharris@csrlink.net>TimeSpan span = (ReceiveTimestamp - OriginateTimestamp) + (TransmitTimestamp - DestinationTimestamp);return span.TotalMilliseconds / 2;}}/// <summary>/// Compute date, given the number of milliseconds since January 1, 1900/// </summary>/// <param name="milliseconds"></param>/// <returns></returns>private DateTime ComputeDate(ulong milliseconds){TimeSpan span = TimeSpan.FromMilliseconds((double)milliseconds);DateTime time = new DateTime(1900, 1, 1);time += span;return time;}/// <summary>/// Compute the number of milliseconds, given the offset of a 8-byte array/// </summary>/// <param name="offset"></param>/// <returns></returns>private ulong GetMilliSeconds(byte offset){ulong intpart = 0, fractpart = 0;for (int i = 0; i <= 3; i++){intpart = 256 * intpart + SNTPData[offset + i];}for (int i = 4; i <= 7; i++){fractpart = 256 * fractpart + SNTPData[offset + i];}ulong milliseconds = intpart * 1000 + (fractpart * 1000) / 0x100000000L;return milliseconds;}/// <summary>/// Compute the 8-byte array, given the date/// </summary>/// <param name="offset"></param>/// <param name="date"></param>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 AMulong milliseconds = (ulong)(date - StartOfCentury).TotalMilliseconds;intpart = milliseconds / 1000;fractpart = ((milliseconds % 1000) * 0x100000000L) / 1000;ulong temp = intpart;for (int i = 3; i >= 0; i--){SNTPData[offset + i] = (byte)(temp % 256);temp = temp / 256;}temp = fractpart;for (int i = 7; i >= 4; i--){SNTPData[offset + i] = (byte)(temp % 256);temp = temp / 256;}}/// <summary>/// Initialize the NTPClient data/// </summary>private void Initialize(){// Set version number to 4 and Mode to 3 (client)SNTPData[0] = 0x1B;// Initialize all other fields with 0for (int i = 1; i < 48; i++){SNTPData[i] = 0;}// Initialize the transmit timestampTransmitTimestamp = DateTime.Now;}/// <summary>/// The IPAddress of the time server we're connecting to/// </summary>private IPAddress serverAddress = null;/// <summary>/// Constractor with HostName/// </summary>/// <param name="host"></param>public NTPClient(string host){//string host = "ntp1.aliyun.com";//string host = "0.asia.pool.ntp.org";//string host = "1.asia.pool.ntp.org";//string host = "www.ntp.org/";// Resolve server addressIPHostEntry hostadd = Dns.GetHostEntry(host);foreach (IPAddress address in hostadd.AddressList){if (address.AddressFamily == AddressFamily.InterNetwork) //只支持IPV4协议的IP地址
                {serverAddress = address;break;}}if (serverAddress == null)throw new Exception("Can't get any ipaddress infomation");}/// <summary>/// Constractor with IPAddress/// </summary>/// <param name="address"></param>public NTPClient(IPAddress address){if (address == null)throw new Exception("Can't get any ipaddress infomation");serverAddress = address;}/// <summary>/// Connect to the time server and update system time/// </summary>/// <param name="updateSystemTime"></param>public void Connect(bool updateSystemTime, int timeout = 3000){IPEndPoint EPhost = new IPEndPoint(serverAddress, 123);//Connect the time serverusing (UdpClient TimeSocket = new UdpClient()){TimeSocket.Connect(EPhost);// Initialize data structure
                Initialize();TimeSocket.Send(SNTPData, SNTPData.Length);TimeSocket.Client.ReceiveTimeout = timeout;SNTPData = TimeSocket.Receive(ref EPhost);if (!IsResponseValid)throw new Exception("Invalid response from " + serverAddress.ToString());}DestinationTimestamp = DateTime.Now;if (updateSystemTime)SetTime();}/// <summary>/// Check if the response from server is valid/// </summary>/// <returns></returns>public bool IsResponseValid{get{return !(SNTPData.Length < SNTPDataLength || Mode != _Mode.Server);}}/// <summary>/// Converts the object to string/// </summary>/// <returns></returns>public override string ToString(){StringBuilder sb = new StringBuilder(512);sb.Append("Leap Indicator: ");switch (LeapIndicator){case _LeapIndicator.NoWarning:sb.Append("No warning");break;case _LeapIndicator.LastMinute61:sb.Append("Last minute has 61 seconds");break;case _LeapIndicator.LastMinute59:sb.Append("Last minute has 59 seconds");break;case _LeapIndicator.Alarm:sb.Append("Alarm Condition (clock not synchronized)");break;}sb.AppendFormat("\r\nVersion number: {0}\r\n", VersionNumber);sb.Append("Mode: ");switch (Mode){case _Mode.Unknown:sb.Append("Unknown");break;case _Mode.SymmetricActive:sb.Append("Symmetric Active");break;case _Mode.SymmetricPassive:sb.Append("Symmetric Pasive");break;case _Mode.Client:sb.Append("Client");break;case _Mode.Server:sb.Append("Server");break;case _Mode.Broadcast:sb.Append("Broadcast");break;}sb.Append("\r\nStratum: ");switch (Stratum){case _Stratum.Unspecified:case _Stratum.Reserved:sb.Append("Unspecified");break;case _Stratum.PrimaryReference:sb.Append("Primary Reference");break;case _Stratum.SecondaryReference:sb.Append("Secondary Reference");break;}sb.AppendFormat("\r\nLocal Time T3: {0:yyyy-MM-dd HH:mm:ss:fff}", TransmitTimestamp);sb.AppendFormat("\r\nDestination Time T4: {0:yyyy-MM-dd HH:mm:ss:fff}", DestinationTimestamp);sb.AppendFormat("\r\nPrecision: {0} s", Precision);sb.AppendFormat("\r\nPoll Interval:{0} s", PollInterval);sb.AppendFormat("\r\nReference ID: {0}", ReferenceID.ToString().Replace("\0", string.Empty));sb.AppendFormat("\r\nRoot Delay: {0} ms", RootDelay);sb.AppendFormat("\r\nRoot Dispersion: {0} ms", RootDispersion);sb.AppendFormat("\r\nRound Trip Delay: {0} ms", RoundTripDelay);sb.AppendFormat("\r\nLocal Clock Offset: {0} ms", LocalClockOffset);sb.AppendFormat("\r\nReferenceTimestamp: {0:yyyy-MM-dd HH:mm:ss:fff}", ReferenceTimestamp);sb.Append("\r\n");return sb.ToString();}/// <summary>/// SYSTEMTIME structure used by SetSystemTime/// </summary>
        [StructLayoutAttribute(LayoutKind.Sequential)]private struct SYSTEMTIME{public short year;public short month;public short dayOfWeek;public short day;public short hour;public short minute;public short second;public short milliseconds;}[DllImport("kernel32.dll")]static extern bool SetLocalTime(ref SYSTEMTIME time);/// <summary>/// Set system time according to transmit timestamp 把本地时间设置为获取到的时钟时间/// </summary>public void SetTime(){SYSTEMTIME st;DateTime trts = DateTime.Now.AddMilliseconds(LocalClockOffset);st.year = (short)trts.Year;st.month = (short)trts.Month;st.dayOfWeek = (short)trts.DayOfWeek;st.day = (short)trts.Day;st.hour = (short)trts.Hour;st.minute = (short)trts.Minute;st.second = (short)trts.Second;st.milliseconds = (short)trts.Millisecond;SetLocalTime(ref st);}}/// <summary>/// Leap indicator field values/// </summary>public enum _LeapIndicator{NoWarning,        // 0 - No warningLastMinute61,    // 1 - Last minute has 61 secondsLastMinute59,    // 2 - Last minute has 59 secondsAlarm            // 3 - Alarm condition (clock not synchronized)
    }/// <summary>/// Mode field values/// </summary>public enum _Mode{SymmetricActive,    // 1 - Symmetric activeSymmetricPassive,    // 2 - Symmetric pasiveClient,                // 3 - ClientServer,                // 4 - ServerBroadcast,            // 5 - BroadcastUnknown                // 0, 6, 7 - Reserved
    }/// <summary>/// Stratum field values/// </summary>public enum _Stratum{Unspecified,            // 0 - unspecified or unavailablePrimaryReference,        // 1 - primary reference (e.g. radio-clock)SecondaryReference,        // 2-15 - secondary reference (via NTP or SNTP)Reserved                // 16-255 - reserved}

 

 

 

使用时:

   //IPAddress ntpserver = IPAddress.Parse("192.39.109.140"); //NTP Serverstring ntpserver = "ntp1.aliyun.com";NTPClient client = new NTPClient(ntpserver);client.Connect(true); //参数为false时只从服务器获取信息,为true时同时自动更新本机时间

 

转载于:https://www.cnblogs.com/xyz0835/p/9322472.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/353280.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

字典树 ZOJ1109 HDU1251 PKU1204 HDU1075

又称单词查找树&#xff0c;Trie树&#xff0c;是一种树形结构&#xff0c;是一种哈希树的变种。典型应用是用于统计&#xff0c;排序和保存大量的字符串&#xff08;但不仅限于字符串&#xff09;&#xff0c;所以经常被搜索引擎系统用于文本词频统计。它的优点是&#xff1a;…

jaxb需要jar包吗_JAXB –不需要注释

jaxb需要jar包吗似乎有一个误解&#xff0c;认为在模型上需要注释才能使用JAXB&#xff08;JSR-222&#xff09;实现。 事实是&#xff0c;JAXB是例外配置&#xff0c;因此仅当您要覆盖默认行为时才需要注释。 在此示例中&#xff0c;我将演示如何在不提供任何元数据的情况下使…

MATLAB均值和标准差

mean(); %均值std(); %标准差

Codeforces Round #498 (Div. 3) F. Xor-Paths

题目链接&#xff1a;F. Xor-Paths 题解&#xff1a;从起点和终点双向搜索在中间相遇时更新答案 1 #include<bits/stdc.h>2 #include<set>3 #include<cstdio>4 #include<iomanip>5 #include<iostream>6 #include<string>7 #include<cst…

创建健壮的微服务架构所涉及的组件

在本文中&#xff0c;我们将简要学习构建强大的微服务应用程序所需的各种软件组件。 在简要了解每个架构组件之前&#xff0c;我们将陈述设计微服务架构时出现的一般查询。 1.微服务架构组件 每当我们创建微服务应用程序时&#xff0c;我们都会想到以下问题 我们将如何注册微…

MATLAB画图命令zz

一、散点图 1&#xff0e;1&#xff0e;命令 plot 功能 线性二维图。在线条多于一条时&#xff0c;若用户没有指定使用颜色&#xff0c;则plot循环使用由当前坐标轴颜色顺序属性&#xff08;current axes ColorOrder property&#xff09;定义的颜色&#xff0c;以区别不同的…

MATLAB判断奇偶数

if mod(n,2)%偶数else%奇数

从percona server 5.7换到mariadb 10.2

过去两年半一直推荐使用percona server&#xff0c;今天开始&#xff0c;因为一些mysql迟迟不不愿意支持的特性&#xff0c;打算换回mariadb 10.2了&#xff0c;具体哪些不说了&#xff0c;总之非常关键&#xff0c;mariadb都支持一两年了&#xff0c;oracle公司因为oracle的原…

jax-rs jax-ws_JAX-WS入门

jax-rs jax-wsJAX-WS代表XML Web Services的Java API。 它是一种Java编程语言API&#xff0c;用于创建Web服务和使用XML进行通信的客户端。 这篇文章是JAX-WS的快速入门。 先决条件 GlassFish与Eclipse集成在一起 。 创建JAX-WS Web服务 1.在Eclipse中创建一个名为“ com.e…

MATLAB求解非线性方程组

function F fun(x)x1 x(1); x2 x(2);F [2*x13*x2-3;3*x12*x2-5];>>fsolve(fun,[0,0])如果有变系数如下&#xff1a; function F fun(x,a,b)x1 x(1); x2 x(2);F [a(1)*x1b(1)*x2-3;a(2)*x1b(2)*x2-5];>>fsolve(fun,[0,0],[],a,b);%中间加一个[],后面传参数即…

lingo解题报告内容解释

1.2菜单介绍 1.2.1 File 1 New 新建一个窗口,当你执行这个命令时,会出现如下对话框: 你可以在对话框中选择你想要建立的类型.类型如下: 1)扩展名为(*.lg4) LG4格式是LINGO4.0的版本,是在Windows下最主要的储存文件格式,这种格式支持字体格式,自定义格式以及动态连接, LG4以二进…

OpenShift上的无痛集装箱化JBoss通用贷款处理

我们从头到尾讨论了各个层次&#xff0c;但尚未为您提供除Red Hat之外的任何应用程序开发工具。我们一直在讨论为什么应用程序开发人员在App Dev Cloud Stack系列中不能再忽略其堆栈了。 容器开发套件&#xff08;CDK&#xff09; 。 到目前为止&#xff0c;您所拥有的只是一个…

多任务编程—多进程

什么是多任务编程&#xff1f; 多任务编程其实和计算机系统内核有关&#xff0c;通过程利用多个计算机内核同时执行程序&#xff0c;以此来提升程序执行的效率。 多任务编程其中包括&#xff0c;多进程、多线程和多协程&#xff0c;这三种多任务编程各有各的优点和缺点&#xf…

MATLAB数值取整

fix(x);%截尾取整&#xff0c;下取整floor(x);%高斯取整&#xff0c;不超过x的最大整数ceil(x);%大于x的最小整数&#xff0c;上取整round(x);%四舍五入取整

Tomcat权威指南-读书摘要系列6

6. Tomcat 安全防护 使用SecurityManager 在Tomcat中&#xff0c;决定安全策略的配置文件是$CATALINA_HOME/conf/catalina.policy&#xff0c;在用-security选项调用Tomcat的时候&#xff0c;JVM读取这一文件。以安全模式启动Tomcat.\catalina.bat start -security 安全漏洞 Cr…

MATLAB找波峰波谷

全局波峰波谷&#xff1a;max();min();所有波峰波谷&#xff1a;findpeaks();pks findpeaks(data) [pks,locs] findpeaks(data) ------pks 对应峰值&#xff0c;locs 对应峰值位数 [...] findpeaks(data,minpeakheight,mph)----mph 设定峰值的最小高度 [...] findpeaks(dat…

chrome 浏览器全屏操作

chrome.exe -kiosk [网页]转载于:https://www.cnblogs.com/yang95/articles/9335975.html

java锁实现_Java锁实现

java锁实现我们都将第三方库用作开发的正常部分。 通常&#xff0c;我们无法控制其内部。 JDK随附的库是一个典型示例。 这些库中的许多库都使用锁来管理争用。 JDK锁具有两种实现。 一个使用原子CAS样式指令来管理索赔过程。 CAS指令往往是最昂贵的CPU指令类型&#xff0c;并且…

2023年12月青少年机器人技术等级考试(五级) 实操试卷

主题&#xff1a;按键控制心形图案交互显示 器件&#xff1a;ESP32主控板1块&#xff0c;按键模块1个&#xff0c;8x8LED点阵1个&#xff0c;74HC595移位寄存器芯片&#xff08;或模块&#xff09;及相应辅件。以上模块也可使用分立器件结合面包板搭建。 任务要求&#xff1a; …

MATLAB正太分布函数

normcdf(x); %标准正态分布的分布函数。 normcdf(x,mu,sigma); %带平均值和方差μ和σ的正态分布&#xff0c;标准正态分布就是mu0,sigma1的特例。%例如>> normcdf(0,0,1)ans 0.5>> normcdf(inf,0,1)ans 1>> normcdf(-inf,0,1)ans 0