# Call with async method

**URL:** <https://www.ruby-forum.com/t/call-with-async-method/120486>\
**Category:** Ruby\
**Created:** [November 17, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/call-with-async-method/120486 "2007-11-17T14:14:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 17, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/1 "2007-11-17T14:14:04Z")

</div>

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

* * *

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 17, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/2 "2007-11-17T15:12:09Z")

</div>

K. R. wrote:

> Thanks for helping…  
> 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?

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 17, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/3 "2007-11-17T17:22:26Z")

</div>

2007/11/17, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > * * *
> 
> 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

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 19, 2007, 7:53am UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/4 "2007-11-19T07:53:04Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 19, 2007, 9:46am UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/5 "2007-11-19T09:46:34Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 19, 2007, 9:40am UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/6 "2007-11-19T09:40:45Z")

</div>

2007/11/19, K. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [November 19, 2007, 9:56am UTC](https://www.ruby-forum.com/t/call-with-async-method/120486/7 "2007-11-19T09:56:01Z")

</div>

2007/11/19, K. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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
