Created
December 21, 2009 02:47
-
-
Save visfleet/260730 to your computer and use it in GitHub Desktop.
Breaks DNSSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
require 'logger' | |
require 'dnssd' | |
# The following gist stops DNSSD from registering a service. On Mac OS X you | |
# can run: | |
# > dns-sd -B | |
# to see services being added and removed. Or altnatively look in Safari's Bonjour | |
# bookmark. When working you'll see a 'BreakDNSSD' service being added, and only | |
# removed once the process is stopped. When not working it either never shows up | |
# or shows up breifly, but is then removed even through the process is still running. | |
# | |
# Commenting out some lines (see comment 1. below) fixes it, and changing the speed | |
# at which BreakDNSSD reads from $stdin fixes it (see comment 2,3,4 at bottom). | |
# Help!! | |
class BreakDNSSD | |
def initialize | |
DNSSD.register!("BreakDNSSD", "_http._tcp", nil, 9070) | |
@logger = Logger.new("test.log") | |
end | |
def start | |
# 1. Commenting out next line fixes it!??!?! | |
@logger.info "Starting" | |
EM.run do | |
conn = EM.watch($stdin, HandleMessage) | |
conn.notify_readable = true | |
end | |
end | |
end | |
module HandleMessage | |
def notify_readable | |
msg = $stdin.gets | |
p msg | |
end | |
end | |
BreakDNSSD.new.start | |
# Doesn't register service: | |
# 2. > while true; do echo "hi there"; done | ruby break_dnssd.rb | |
# Registers service: | |
# 3. > while true; do echo "hi there"; sleep 1; done | ruby break_dnssd.rb | |
# Briefly registers service, then is removed after a few seconds. | |
# 4. > while true; do echo "hi there"; sleep 0.001; done | ruby break_dnssd.rb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment