RubyCocoa で SCNetworkReachability を使ってみました。
require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/SystemConfiguration.framework'
include OSX
# Reachability Call Back
networkReachabilityCallBack = proc do |target, flags, info|
print "NetworkReachabilityCallBack: %d\n" % flags
end
# Initialize Reachablity
reachability = SCNetworkReachabilityCreateWithName(nil, "balunsoftware.jp")
unless reachability != nil
print "SCNetworkReachabilityCreateWithName error"
exit 1
end
unless SCNetworkReachabilitySetCallback(reachability, networkReachabilityCallBack, nil)
print "SCNetworkReachabilitySetCallback error"
exit 1
end
unless SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetCurrent(), KCFRunLoopDefaultMode)
print "SCNetworkReachabilityScheduleWithRunLoop error"
exit 1
end
begin
CFRunLoopRun()
rescue Interrupt
end
確認バージョン
- ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
- RubyCocoa-1.0.5-OSX10.7/10.8