[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

call with async method

K. R.

11/17/2007 1:14:00 PM

Hi @all

I'm developing a tool who sniff the networktraffic on the nic. I would
like to call the method asynchron from a other pc. I realize this
problem with xmlrpc4r. To sniff the networkpackets, I use the pcaplet.

Now, I want to stop the sniffing method also at the remote side. The
idea is to set a global flag $state to boolean false. But it doesn't run
correctly. You can see below the code from the remote class.

Thanks for helping...

______________Sniffing class____________________

class Sniffer
$state = true

def start_sniffing
@pcaplet = Pcaplet.new("-i eth0")
# ...and so on....

for pkt in @pcaplet
puts pkt.time
break if $state == false # stop sniffing
end
end

def stop_sniffing
$state = false
end
end
_________________________________________________
--
Posted via http://www.ruby-....

6 Answers

Alex Young

11/17/2007 2:10:00 PM

0

K. R. wrote:
> Hi @all
>
> I'm developing a tool who sniff the networktraffic on the nic. I would
> like to call the method asynchron from a other pc. I realize this
> problem with xmlrpc4r. To sniff the networkpackets, I use the pcaplet.
>
> Now, I want to stop the sniffing method also at the remote side. The
> idea is to set a global flag $state to boolean false. But it doesn't run
> correctly. You can see below the code from the remote class.
>
> Thanks for helping...
>
> ______________Sniffing class____________________
>
> class Sniffer
> $state = true
>
> def start_sniffing
> @pcaplet = Pcaplet.new("-i eth0")
> # ...and so on....
>
> for pkt in @pcaplet
> puts pkt.time
> break if $state == false # stop sniffing
> end
> end
>
> def stop_sniffing
> $state = false
> end
> end
> _________________________________________________

Not sure why you want a global for this. Wouldn't it be better to set
an @state instance variable in Sniffer's initialize method, and refer to
that in start_sniffing and stop_sniffing?

--
Alex

Robert Klemme

11/17/2007 4:21:00 PM

0

2007/11/17, Alex Young <alex@blackkettle.org>:
> K. R. wrote:
> > Hi @all
> >
> > I'm developing a tool who sniff the networktraffic on the nic. I would
> > like to call the method asynchron from a other pc. I realize this
> > problem with xmlrpc4r. To sniff the networkpackets, I use the pcaplet.
> >
> > Now, I want to stop the sniffing method also at the remote side. The
> > idea is to set a global flag $state to boolean false. But it doesn't run
> > correctly. You can see below the code from the remote class.
> >
> > Thanks for helping...
> >
> > ______________Sniffing class____________________
> >
> > class Sniffer
> > $state = true
> >
> > def start_sniffing
> > @pcaplet = Pcaplet.new("-i eth0")
> > # ...and so on....
> >
> > for pkt in @pcaplet
> > puts pkt.time
> > break if $state == false # stop sniffing
> > end
> > end
> >
> > def stop_sniffing
> > $state = false
> > end
> > end
> > _________________________________________________
>
> Not sure why you want a global for this. Wouldn't it be better to set
> an @state instance variable in Sniffer's initialize method, and refer to
> that in start_sniffing and stop_sniffing?

Definitively. And also: KR, where do you do the sniffing? Is it in
Pcaplet's constructor? In that case the flag would be useless.

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

K. R.

11/19/2007 6:53:00 AM

0

> Definitively. And also: KR, where do you do the sniffing? Is it in
> Pcaplet's constructor? In that case the flag would be useless.

No, I don't sniff in the constructor. But with xmlrpc4r, I have a big
problem. When I want to start the Serverapplication (server =
XMLRPC::Server.new(ip, "/RPC2", 20000) and call the serve method, my
application needs 20 seconds to start correctly. After the starting
phase, all response of connection-requests have a delay to 20 seconds.
--
Posted via http://www.ruby-....

Robert Klemme

11/19/2007 8:40:00 AM

0

2007/11/19, K. R. <mcse@palstek.ch>:
> > Definitively. And also: KR, where do you do the sniffing? Is it in
> > Pcaplet's constructor? In that case the flag would be useless.
>
> No, I don't sniff in the constructor. But with xmlrpc4r, I have a big
> problem. When I want to start the Serverapplication (server =
> XMLRPC::Server.new(ip, "/RPC2", 20000) and call the serve method, my
> application needs 20 seconds to start correctly. After the starting
> phase, all response of connection-requests have a delay to 20 seconds.

Ugly. Did you find out where the time is spent? Is using DRb an option?

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

K. R.

11/19/2007 8:47:00 AM

0


> Ugly. Did you find out where the time is spent? Is using DRb an
> option?

yeah the problem is in the serve method from xmlrpc4r. It takes 20
seconds to establish a tcpserver. Now, I'm using the DRb option. But it
seems like the same problem.
--
Posted via http://www.ruby-....

Robert Klemme

11/19/2007 8:55:00 AM

0

2007/11/19, K. R. <mcse@palstek.ch>:
>
> > Ugly. Did you find out where the time is spent? Is using DRb an
> > option?
>
> yeah the problem is in the serve method from xmlrpc4r. It takes 20
> seconds to establish a tcpserver. Now, I'm using the DRb option. But it
> seems like the same problem.

Sounds as if you either have a networking issue (slow DNS loopups?) or
you have a fundamental design issue (i.e. starting a server too
often).

My 0.02EUR...

robert

--
use.inject do |as, often| as.you_can - without end