[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

XMLRPC and Sockets

Robin Wagenaar

11/29/2007 12:40:00 PM

Hi everyone,

I'm currently researching the capabilities of a SmartDust network, my
goal is to build an application that will get statistics from a network
management device.

The device is connected to my networkcontroller, I can request for
information using xml-rpc. This part of the application works (more or
less), but here's the problem.

The device can also detect network events, and spam them back (xml) to
the pc. The procedure is like this:
1. Connect to the management device
2. Login with credentials
3. Ask for a event-port
4. Listen on this port for incoming data

Asking the device for stats was quite straightforward, but I don't have
a clue how to capture/parse the incoming data. (threads? xml-rpc
server?)

I have included some (read: most) information about the device as
attachment, and copy-pasted my basestation-class below. Sorry for the
long-ish post. (EDIT: to bad, the pdf file was slightly too large...)

Everyone told me to go Java, but stubborn me decided to go Ruby, so I
now have to prove Im not a total idiot after all =) Thanks in advance,
'cause I'm really stuck at this one .. =(

#required libraries
require 'xmlrpc/client'
require 'socket'
require 'pp'

class BaseStation

#constructor that will create a token that can be
#used in other xml-rpc requests or an error message
#if the logincredentials are incorrect
def initialize(username, password, url = "192.168.99.100", port =
"4445")
@url = url;
@port = port;
@username = username;
@password = password

begin
@client = XMLRPC::Client.new3({ :port => port, :host => url })
result = @client.call "login", username, password
@token = result
rescue
puts "Something went wrong"
false
end
end

#method that will generate a configuration
#request, the return value depends on the
#querystring
def get_config(depth, query)
begin
result = @client.call "getConfig", @token, depth, query
rescue
puts "Something went wrong"
false
end
end

#method that will subscribe user to all notifications
#the return value is a portnumber where these notifications
#will occur
def get_notification_port(notification = "all")
begin
result = @client.call "subscribe", @token, notification
result[1]
rescue
puts "Something went wrong"
false
end
end

#method that will spam the notifications generated by the
#base-station directly to the terminal
def start_listening_for_notifications(port = 0)
port = get_notification_port()
pp port
server = TCPserver.new("0.0.0.0", get_notification_port())
loop do
Thread.start(server.accept) do |s|
print(server, " is accepted\n")
s.write(Time.now)
print(server, " is gone\n")
s.close
end
end
end


#getter for the token variable
def login_token
@token
end

end
--
Posted via http://www.ruby-....

1 Answer

Robin Wagenaar

11/30/2007 8:29:00 AM

0

ehh... nobody? Anyone?
--
Posted via http://www.ruby-....