Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Stop receiving packet from motes

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Stop receiving packet from motes

    Hi everybody,

    I have a java code that read packets from telosb motes.

    here my main function

     
    public static void main(String[] args) throws Exception {
     
      String source = null;
        if (args.length == 2) {
     
          if (!args[0].equals("-comm")) {
    	       usage();
    	       System.exit(1);
          }
     
          source = args[1];
        }
        else if (args.length != 0) {
          usage();
          System.exit(1);
        }
     
      PhoenixSource phoenix;
     
      if (source == null) {
          phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
       }
       else {
         phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
       }
     
       MoteIF mif = new MoteIF(phoenix); 
     
       Forwarder serial = new Forwarder(mif);
     
     
       }

    and here the Forwarder constructor

    public Forwarder(MoteIF moteIF) {
     
                this.moteIF = moteIF;
                this.moteIF.registerListener(new MyMessageMsg(), this);//  Register a listener for given messages type.
     
      }

    and I have function that invoked when new packet arrive

    public void messageReceived(int to, Message message) {
        MyMessageMsg msg = (MyMessageMsg)message;
     
     
     
     
     
        if(msg.get_area() != 7 ){ 
            System.out.println("-----Recive  New Message -------" ); 
     
     
        }
     
     
     
      }

    my question is : how I can stop packets receiving after receiving 200 packets ?

    I read from here MoteIF

    That I can use "deregisterListener" method to do that

    but I don't know how to do that to stop receiving packets


    please, help me


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Stop receiving packet from motes

    I don't know for sure, but I'll hazard a guess: Count the packets as they arrive in the 'messageReceived' method, and check the count at the end of the 'messageReceived' method. If the count has reached 200, call this.moteIF.deRregisterListener().

  3. The Following User Says Thank You to dlorde For This Useful Post:

    gloor (May 28th, 2011)

  4. #3
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Stop receiving packet from motes

    Thank you so much

    I did the same but I got exceptions.

    the method 'messageReceived' is invoked automatically when one packet arrive

    I couldn't stop this automatic calling with this way and I searched over web but I can't find any similar example

    Any help please

  5. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Stop receiving packet from motes

    Sadly, I'm not clairvoyant, so unless you post the code that shows exactly what you did and full text of the exception messages and stack traces you got, I can't help.

  6. #5
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Stop receiving packet from motes

    The problem is solved.

Similar Threads

  1. Parsing a string to an int while receiving user input?
    By happyxcrab in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 11th, 2011, 05:38 PM
  2. servlet not receiving any data
    By vishal21 in forum Java Servlet
    Replies: 0
    Last Post: March 14th, 2011, 01:01 PM
  3. Replies: 0
    Last Post: March 9th, 2011, 02:58 AM
  4. Replies: 6
    Last Post: October 23rd, 2009, 03:53 AM
  5. Sending and Receiving mail using J2ME without server
    By chals in forum Java ME (Mobile Edition)
    Replies: 5
    Last Post: June 2nd, 2009, 09:59 AM