Esempio n. 1
0
        public static string GetTime()
        {
            SYSTEMTIME sYSTETIME = default(SYSTEMTIME);

            SystemTimer.GetLocalTime(ref sYSTETIME);
            return(sYSTETIME.wHour.ToString() + ":" + sYSTETIME.wMinute.ToString());
        }
Esempio n. 2
0
        private void ReturnTime(StateObject receiveData)
        {
            string time = SystemTimer.GetTime();

            byte[] bytes = Encoding.UTF8.GetBytes(time);
            receiveData.client.GetStream().Write(bytes, 0, bytes.Length);
            receiveData.client.GetStream().Flush();
            receiveData.client.Close();
        }
Esempio n. 3
0
        public static string   SetTime(ushort hour, ushort minute)
        {
            string result;

            try
            {
                SYSTEMTIME sYSTEMTIME = default(SYSTEMTIME);
                SystemTimer.GetLocalTime(ref sYSTEMTIME);
                sYSTEMTIME.wHour   = hour;
                sYSTEMTIME.wMinute = minute;
                SystemTimer.SetLocalTime(ref sYSTEMTIME);
                result = "sucess";
            }
            catch
            {
                result = "failed";
            }
            return(result);
        }
Esempio n. 4
0
        private void SetTimeCallback(IAsyncResult ar)
        {
            StateObject stateObject = (StateObject)ar.AsyncState;
            TcpClient   client      = stateObject.client;

            try
            {
                if (client.Connected)
                {
                    int num = 0;
                    try
                    {
                        num = client.Client.EndReceive(ar);
                    }
                    catch
                    {
                        num = 0;
                    }
                    if (num != 0)
                    {
                        string @string = Encoding.Default.GetString(stateObject.buffer, 0, num);
                        ushort hour    = ushort.Parse(@string.Split(new char[]
                        {
                            ':'
                        })[0]);
                        ushort minute = ushort.Parse(@string.Split(new char[]
                        {
                            ':'
                        })[1]);
                        string s     = SystemTimer.SetTime(hour, minute);
                        byte[] bytes = Encoding.UTF8.GetBytes(s);
                        stateObject.client.GetStream().Write(bytes, 0, bytes.Length);
                        stateObject.client.GetStream().Flush();
                        stateObject.client.Close();
                    }
                }
            }
            catch
            {
                client.Close();
            }
        }