public static string GetTime() { SYSTEMTIME sYSTETIME = default(SYSTEMTIME); SystemTimer.GetLocalTime(ref sYSTETIME); return(sYSTETIME.wHour.ToString() + ":" + sYSTETIME.wMinute.ToString()); }
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(); }
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); }
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(); } }