返回顶部

收藏

ruby 自动对时器 win32

更多
#! rubyw.exe
# encoding: gbk
require 'socket'
require 'time'
require 'cstruct/win32struct'
require 'cstruct'
require 'windows/time'
include Windows::Time

class Systemtime < Win32Struct
    int16:wYear
    WORD :wMonth
    WORD:wDayOfWeek
    WORD:wDay
    WORD:wHour
    WORD:wMinute
    WORD:wSecond
    WORD:wMilliseconds
end

def set_clock(time)
    local_time = Systemtime.new
    local_time.wYear          = time.year
    local_time.wMonth         = time.month
    local_time.wDay           = time.day
    local_time.wHour          = time.hour
    local_time.wMinute        = time.min
    local_time.wSecond        = time.sec
    local_time.wMilliseconds  = time.usec/1000
    SetLocalTime(local_time.data)
end

$geted = false
def g(s)
    exit if $geted
    t=s.recv(2000).match(/date:.*$/i)[0]
    sleep 0.5
    p t
    $geted = true
    puts 'get time'
    set_clock(Time.parse t[5..-1])
end

`title 自动对时`
20.times{|x|
    p 20-x
    sleep 1
}

#取http服务器时间
TCPSocket.open("www.g.cn", 80) {|s|
    s.send "GET / HTTP/1.0\\r\\n\\r\\n", 0
    20.times{ g(s) } 
}
#该片段来自于http://outofmemory.cn

标签:ruby,系统

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-06-22 12:18:01Ruby调用WindowsAPI模拟按键 by LeoSun
  2. 2014-10-28 19:54:48检查SSH by LeoSun
  3. 2014-07-16 11:13:00Linux 一键静音脚本 by 好好学习啊
  4. 2014-08-19 10:34:03ruby使用Win32API操作鼠标 by 杨洋
  5. 2014-07-21 21:27:37用win api 显示一个窗体 by LeoSun
  6. 2014-08-21 11:46:00Ruby 在 Windows 下播放声音 by 胡晋
  7. 2014-11-27 10:15:02一键push 到 所有 git 仓库 by 好好学习啊
  8. 2014-08-16 19:58:35Linux 带宽使用情况 by LeoSun
  9. 2014-05-24 18:50:55Ruby 在 Windows 下读取键盘输入 by digua
  10. 2014-06-29 20:25:10Ruby从剪贴板中取数据 by JustForFly
  11. 2014-05-24 19:08:58Ruby 在 IE 中打开对话框 by Jamin

发表评论