On Nov 15, 2007, at 9:22 PM, James Edward G. II wrote:
from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
methodResponse' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in
start’
eventually.
I now understand this error and why I was getting it. Your handler
for “sniffer.connect” returns a Sniffer object, which is not a legal
return value for XML-RPC. You could use a combination of
Config::ENABLE_MARSHALLING and XMLRPC::Marshallable to get Ruby’s
implementation to dump it, but that doesn’t seem to be what you
wanted here.
I added a simple:
true
to the end of all of your handlers and then the server and client ran
for me.
Here are the total changes I made. First, the server:
#!/usr/bin/env ruby -wKU
require ‘xmlrpc/server’
class Sniffer
def initialize(port, ip)
@port = port
@ip = ip
end
def start
# Use the pcap library to sniff at port @port from ip @ip
# …
puts “Started sniffing…”
end
def stop
# Stop the sniffer
# …
puts “Stopped sniffing…”
end
end
s = XMLRPC::Server.new(8080)
sniffer = nil
s.add_handler(“sniffing.connect”) do |port, ip|
sniffer = Sniffer.new(port, ip)
true
end
s.add_handler(“sniffing.start”) do
sniffer.start if sniffer
true
end
s.add_handler(“sniffing.stop”) do
sniffer.stop if sniffer
true
end
s.serve
END
And here is my client:
#!/usr/bin/env ruby -wKU
require ‘xmlrpc/client’
server = XMLRPC::Client.new(“localhost”, “/RPC2”, 8080)
server.call(“sniffing.connect”, 25000, “192.168.10.10”)
Thread.new {
server.call_async(“sniffing.start”)
}
Now sending network traffic
…
sleep 2
server.call(“sniffing.stop”)
END
Will these scripts run for you now, as is?
James Edward G. II