Skip to content

Instantly share code, notes, and snippets.

@davidlee
Created March 15, 2009 03:12
Show Gist options
  • Save davidlee/79286 to your computer and use it in GitHub Desktop.
Save davidlee/79286 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
@config = {
:host => "127.0.0.1",
:port => 9666
}
puts DATA.read
module XMLSocketServer
CR = 0.chr # ZERO BYTE
# helpers
def log( msg, level = :debug )
STDOUT.puts msg
end
def policy_request?( data )
data == "<policy-file-request/>\000"
end
def policy_document
@policy ||= DATA.read
end
def push( data )
if data[-1] != 0 # \000
data << CR
end
send_data( data )
end
# the EventMachine hook
def receive_data(data)
log( "RECVD # => #{data.inspect}" )
if policy_request?( data )
push( policy_document )
else
log( " [ == what now ? == ] " )
end
end
end
EventMachine::run do
EventMachine::start_server( @config[:host], @config[:port], XMLSocketServer )
end
__END__
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
<allow-access-from domain="127.0.0.1" to-ports="*" />
<allow-access-from domain="localhost" to-ports="*" />
</cross-domain-policy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment