On Nov 15, 2007, at 9:22 PM, James Edward Gray II wrote:

>> In method start of class sniffer, I actually use a while loop  
>> until the sender stop the sendingstream.
>
> I have sat over here fiddling with this thing half the night and I  
> can't seem to get that far.  When I run your server and client I  
> get a type error for the arguments.  I see this on error the client:
>
> /usr/local/lib/ruby/1.8/xmlrpc/client.rb:546:in `do_rpc': HTTP- 
> Error: 500 Internal Server Error  (RuntimeError)
>         from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2'
>         from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
>         from client.rb:6
>
> And the server reports:
>
> [2007-11-15 21:15:20] ERROR RuntimeError: Wrong type!
>         /usr/local/lib/ruby/1.8/xmlrpc/create.rb:274:in `conv2value'
>         /usr/local/lib/ruby/1.8/xmlrpc/create.rb:148:in  
> `methodResponse'
>         /usr/local/lib/ruby/1.8/xmlrpc/create.rb:147:in `collect'
>         /usr/local/lib/ruby/1.8/xmlrpc/create.rb:147:in  
> `methodResponse'
>         /usr/local/lib/ruby/1.8/xmlrpc/server.rb:378:in `handle'
>         /usr/local/lib/ruby/1.8/xmlrpc/server.rb:310:in `process'
>         /usr/local/lib/ruby/1.8/xmlrpc/server.rb:760:in `service'
>         /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
>         /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:173:in  
> `start_thread'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:162:in  
> `start_thread'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
>         /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
>         /usr/local/lib/ruby/1.8/xmlrpc/server.rb:648:in `serve'
>         server.rb:37
> localhost - - [15/Nov/2007:21:15:20 CST] "POST /RPC2 HTTP/1.1" 500 292
> - -> /RPC2
>
> I haven't figured this out yet, but I'm still trying.  I'll get it  
> 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 Gray II