BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-01-2008, 07:44 AM   #1
JoelParker
New Member
 
Join Date: Aug 2008
Model: Curve
PIN: N/A
Carrier: T-Mobile
Posts: 13
Default I/O Exception Thrown when using Message Listener

Please Login to Remove!

This class was working great fro sending sms messages until I added a message listener, know it throws an IOException every time I start the thread. Any Ideas, how to fix this ?

Below is the class and the message listener:

Code:
private static final class SmsMessage
    {
        private String _address;
        private String _msg;

        public SmsMessage(String address, String msg)
        {
            _address = address;
            _msg = msg;
        }
       
        public Message toMessage(MessageConnection mc)
        {
            TextMessage m = (TextMessage)mc.newMessage(MessageConnection.TEXT_MESSAGE,"sms://" + _address);
            m.setPayloadText(_msg);
            return m;
        }
    } // SmsMessage
   
   private final class SendThread extends Thread
    {
        private static final int TIMEOUT = 500; // ms
        private Vector _msgs = new Vector(10); // Queue of 10
        private volatile boolean _start = false;

        // queue requests
        public synchronized void send(String address, String msg)
        {
            _start = true;
            _msgs.addElement(new SmsMessage(address, msg));
        }

        public synchronized void stop()
        {
            _stop = true;
            try {
                if ( _mc != null ){
                    _mc.close();
                }
            } // catch (IOException e ) {
                catch (Throwable t) {
                t.printStackTrace();
                System.exit(0);
            }
              
        }

        public void run()
        {
            try {
                //closed by the stop() method
                _mc = (MessageConnection)Connector.open("sms://");
               
                if (_mc != null)
                {
                    // set a listener to trap outgoing sms messages
                    _mc.setMessageListener(new OutboundSMSListener());
                }
                for(;;)
                {
                    while( !_start && !_stop)
                    {
                        try {
                            sleep(TIMEOUT);
                        } // catch (InterruptedException e) {
                            catch (Throwable t) {
                                t.printStackTrace();
                                System.exit(0);
                            }
                    }
                    if ( _stop )
                    {
                        return;
                    }
   
                    while(true)
                    {
                        try {
                            SmsMessage sms = null;
                            synchronized (this)
                            {
                                if ( !_msgs.isEmpty() )
                                {
                                    sms = (SmsMessage)_msgs.firstElement();
                                    // take it out of the queue once we sent it
                                    _msgs.removeElement(sms);
                                }
                                else
                                {
                                    _start = false;
                                    break;
                                }
                            }
                           
                            _mc.send(sms.toMessage(_mc));
   
                        } // catch (IOException e) {
                            catch (Throwable t) {
                                t.printStackTrace();
                                System.exit(0);
                        }
                    }
                }
            } // catch (IOException e)
              catch (Throwable t) {
                t.printStackTrace();
                System.exit(0);
              }
        }
    } // SendThread
   
    private static final class OutboundSMSListener implements OutboundMessageListener
    {
        public void notifyIncomingMessage(MessageConnection messageconnection)
        {
            // we don't care about incoming sms messages right now
        }
       
        public void notifyOutgoingMessage(Message message)
        {
            Dialog.alert("Detected An Outgoing SMS Event");
        }
    }
Offline  
Old 12-01-2008, 03:43 PM   #2
jonberry
Thumbs Must Hurt
 
Join Date: Apr 2005
Model: 950
Carrier: T-Mobile
Posts: 185
Default

Are you sure the IOException is coming when from the Listener?
Offline  
Old 12-02-2008, 03:04 PM   #3
Jebadiah
New Member
 
Join Date: Dec 2008
Model: 8700
PIN: N/A
Carrier: AT&T
Posts: 4
Default

Hey Joel, I am creating a similar application. I am not sure why you're getting an exception. I suggest debugging it on the device.

On another note, have you figured out how to store the sent message in the Sent folder?
Offline  
Old 02-10-2009, 01:04 AM   #4
aashu.jaidka
New Member
 
Join Date: Sep 2008
Model: 8800
PIN: N/A
Carrier: airtel
Posts: 4
Default

it should be like :
_mc = (MessageConnection)Connector.open("sms://:portnumber");
where portnumber is 0 or 6222
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Tektronix 7904 Oscilloscope Mainframe  w/ 2x 7A26 2x 7B92A Modules picture

Tektronix 7904 Oscilloscope Mainframe w/ 2x 7A26 2x 7B92A Modules

$399.97



Chroma 6312 DC Electronic Load Mainframe  picture

Chroma 6312 DC Electronic Load Mainframe

$239.96



Fluke Networks Versiv Modular Mainframe AS IS picture

Fluke Networks Versiv Modular Mainframe AS IS

$1200.00



Tektronix TM506 Modular 6-bay Mainframe Compartment for power 6-Slot READ DESCRP picture

Tektronix TM506 Modular 6-bay Mainframe Compartment for power 6-Slot READ DESCRP

$124.95



ILX Lightwave LDC3908 Laser Diode Controller Mainframe with Key picture

ILX Lightwave LDC3908 Laser Diode Controller Mainframe with Key

$480.00



MT9810A ANRITSU OPTICAL TEST SET MAINFRAME picture

MT9810A ANRITSU OPTICAL TEST SET MAINFRAME

$300.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.