Skip to main content

J2ME WMA: Unable to send text SMS

No replies
deepujain
Offline
Joined: 2005-11-23

Hi,
I am new to J2ME and trying to develop a JAVA app to send and receive SMS. I have written a receiver that will receive the SMS and a sender that will send text SMS. I ran the receiver from Eclipse . My receiver has registered to listen for any incoming sms.

mc = newMessageConnection("sms://:5000");
mc.setMessageListener(this);

I ran the sender to send the SMS as
String url = "sms://+5550000:5000";
mc = newMessageConnection(url);
sendTextMessage(mc,"Test SMS",url);
Code:
public void sendTextMessage(MessageConnection mc, String msg, String url) {
try {
System.out.println("mc:" + mc);
TextMessage tmsg = (TextMessage) mc
.newMessage(MessageConnection.TEXT_MESSAGE);
System.out.println("url:" + url);
if (url != null)
tmsg.setAddress(url);
tmsg.setPayloadText(msg);
mc.send(tmsg);
System.out.println("Message sent ");
} catch (Exception e) {
// Handle the exception...
System.out.println("sendTextMessage " + e);
e.printStackTrace();
}
}
When i run this code via Eclipse (Unable to run in debug mode) so i ran it jst like that. I get an exception

Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\temp.MediaControlSkin2
Running with locale: English_United States.1252
Running in the identified_third_party security domain
mc:com.sun.midp.io.j2me.sms.Protocol@1cb37664
url:sms://+5550000:5000
sendTextMessage java.io.IOException: Connection closed
java.io.IOException: Connection closed
at com.sun.midp.io.j2me.datagram.Protocol.ensureOpen(+16)
at com.sun.midp.io.j2me.datagram.Protocol.newDatagram(+4)
at com.sun.midp.io.j2me.sms.DatagramImpl.send(+245)
at com.sun.midp.io.j2me.sms.Protocol.send(+430)
at com.silentsms.TestMessageSender.sendTextMessage(+85)
at com.silentsms.TestMessageSender.startApp(+29)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)

The receiver number was set to : +5550000 and hence the sent to URL is String url = "sms://+5550000:5000";
mc = newMessageConnection(url);.

Can anyone please let me what is wrong with the code.

I have installed WTK2.5.2_01 with JDK 1.5.0_17.
I am using javax.wireless.messaging.MessageConnection; APIs to send and receive TEXT sms. I followed the article posted @ http://developers.sun.com/mobility/midp/articles/wma/

Any help is appreciated