473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problem in capturing incoming message

49
hi all,

I have an application to send and recieve an SMS but my application is not catching the incoming message.

can anyone tell what's wrong with the following code:


Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.microedition.midlet.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.io.*;
  5. import javax.wireless.messaging.*;
  6. import java.io.*;
  7.  
  8. import java.util.*;
  9.  
  10.  
  11. public class MessageReceive extends MIDlet implements CommandListener, MessageListener 
  12. {
  13.  
  14.  
  15. private Command exitCommand; 
  16.  
  17. private Command getMsgCommand;
  18.  
  19.  
  20. private Display display;
  21.  
  22. Form displayForm;
  23. public static String msgReceived ;
  24. Thread Recivethread;
  25.  
  26. MessageConnection serverConn;
  27.  
  28.  
  29.  
  30.  
  31.  
  32. public MessageReceive () {
  33. display = Display.getDisplay(this);
  34. exitCommand = 
  35. new Command("Exit", Command.SCREEN, 1);
  36. getMsgCommand = 
  37. new Command("Get", Command.SCREEN, 1);
  38.  
  39.  
  40. }
  41.  
  42.  
  43. public void startApp() {
  44. displayForm = new Form("Get Message");
  45.  
  46. displayForm.addCommand(exitCommand);
  47. displayForm.addCommand(getMsgCommand);
  48.  
  49. displayForm.setCommandListener(this);
  50.  
  51. display.setCurrent(displayForm);
  52.  
  53. try
  54. {
  55. Alert rrrecAlert = new Alert("","Mesage connection open",null, AlertType.INFO);
  56. rrrecAlert.setTimeout(Alert.FOREVER);
  57. display.setCurrent(rrrecAlert, displayForm);
  58. serverConn = (MessageConnection)Connector.open("sms://:5000",Connector.READ);
  59.  
  60. serverConn.setMessageListener(this);
  61. Alert ecAlert = new Alert("","Mesage Listener.....",null, AlertType.INFO);
  62. ecAlert.setTimeout(Alert.FOREVER);
  63. display.setCurrent(ecAlert, displayForm);
  64. Recivethread = new Thread(new CatchRecMsg());
  65. Recivethread.start();
  66.  
  67. }
  68. catch (IOException ioExc)
  69. {
  70. Alert ecAlert = new Alert("","Server connection could not be obtained",null, AlertType.INFO);
  71. ecAlert.setTimeout(Alert.FOREVER);
  72. display.setCurrent(ecAlert, displayForm);
  73.  
  74.  
  75. }
  76.  
  77.  
  78. public synchronized void notifyIncomingMessage(MessageConnection conn) {
  79.  
  80. Alert ecAlert = new Alert("","Mesage Incoming Listener.....",null, AlertType.INFO);
  81. ecAlert.setTimeout(Alert.FOREVER);
  82. display.setCurrent(ecAlert, displayForm);
  83. if (conn == serverConn) {
  84.  
  85. Recivethread = new Thread(new CatchRecMsg());
  86. Recivethread.start();
  87. }
  88. else{
  89. Alert eAlert = new Alert("","Mesage conn not equals.....",null, AlertType.INFO);
  90. eAlert.setTimeout(Alert.FOREVER);
  91. display.setCurrent(eAlert, displayForm);
  92.  
  93. }
  94.  
  95. }
  96.  
  97. public class CatchRecMsg implements Runnable
  98. {
  99. public void run() {
  100. try{
  101.  
  102. Alert recAlert = new Alert("","This is getting",null, AlertType.INFO);
  103. recAlert.setTimeout(Alert.FOREVER);
  104. display.setCurrent(recAlert, displayForm);
  105.  
  106. try {
  107. System.out.println("In the catchReceive ");
  108.  
  109. Message msg = serverConn.receive();
  110. System.out.println("Out the the catchReceive ");
  111. if (msg instanceof TextMessage) {
  112. TextMessage tmsg = (TextMessage)msg;
  113. msgReceived = tmsg.getPayloadText();
  114. recAlert = new Alert("","We got the masg Text : "+msgReceived,null, AlertType.INFO);
  115. recAlert.setTimeout(Alert.FOREVER);
  116. display.setCurrent(recAlert, displayForm);
  117. displayForm.append(msgReceived);
  118. display.setCurrent(displayForm);
  119.  
  120. }
  121. else 
  122.  
  123. if (msg instanceof BinaryMessage) {
  124. BinaryMessage bmsg = (BinaryMessage)msg;
  125. byte[] data = bmsg.getPayloadData();
  126.  
  127. msgReceived = data.toString();
  128. displayForm.append(msgReceived);
  129. display.setCurrent(displayForm);
  130.  
  131. recAlert = new Alert("","We got the masg Binary : " +msgReceived,null, AlertType.INFO);
  132. recAlert.setTimeout(Alert.FOREVER);
  133. display.setCurrent(recAlert, displayForm);
  134. }
  135.  
  136. else
  137. {
  138. recAlert = new Alert("","Msg getting is nothing"+msg,null, AlertType.INFO);
  139. recAlert.setTimeout(Alert.FOREVER);
  140. display.setCurrent(recAlert, displayForm);
  141. }
  142. }
  143. catch (Exception e) {
  144. recAlert = new Alert("","Error occurs in receive()"+e,null, AlertType.INFO);
  145. recAlert.setTimeout(Alert.FOREVER);
  146. display.setCurrent(recAlert, displayForm);
  147. }
  148.  
  149. } catch (Exception e) {
  150. Alert recAlert = new Alert("","I got error here",null, AlertType.INFO);
  151. recAlert.setTimeout(Alert.FOREVER);
  152. display.setCurrent(recAlert, displayForm);
  153. }
  154. }
  155.  
  156.  
  157.  
  158.  
  159. public void pauseApp()
  160. { }
  161.  
  162.  
  163.  
  164. public void destroyApp(boolean unconditional) { 
  165.  
  166.  
  167.  
  168. }
  169.  
  170.  
  171. public void commandAction(
  172. Command c, Displayable s) {
  173. if (c == exitCommand) {
  174. destroyApp(false);
  175. notifyDestroyed();
  176. }
  177.  
  178. if (c == getMsgCommand) {
  179. try
  180. {
  181.  
  182. displayForm.append(msgReceived);
  183.  
  184. display.setCurrent(displayForm);
  185. Alert ecAlert = new Alert("","nothing there .....",null, AlertType.INFO);
  186. ecAlert.setTimeout(Alert.FOREVER);
  187. display.setCurrent(ecAlert, displayForm);
  188.  
  189. }
  190. catch (Exception exc)
  191. {
  192. exc.printStackTrace();
  193. }
  194.  
  195.  
  196. }
  197. }
  198.  
  199.  
  200.  
  201. }
  202.  


regards
LTCCTL
Dec 24 '08 #1
0 1885

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dan | last post by:
A Newbie needs help! Is it possible, in PHP, to capture the resulting HTML of a submitted form returning from a server and incorporate that HTML into say a table, or some predefined layout? I...
5
by: Andrew Dixon | last post by:
Hi Everyone. Ok I have a problem getting the following regex to work in Java. <script*>(.|\r|\n)+?</script> It works fine in EditPad Pro but in Java it causes the following error message...
5
by: Benny | last post by:
Hi, Is there a script/compoenent which can capture Faxes and store that in a DB using a unique ID? Any help will be greatly appriciated. Thanks, Benny
5
by: Lasse Edsvik | last post by:
Hello I have this: public SqlParameter GetParameter(string sqlparam) { SqlParameter param = cmd.Parameters.Add(sqlparam);
14
by: Brent Burkart | last post by:
I am trying to capture the Windows Authenticated username, but I want to be able to capture the login name that exists in IIS, not Windows. In order to enter my company's intranet through the...
4
by: tma | last post by:
How does one capture the IP address of an incoming connection to an ASPX page?
9
by: google_groups3 | last post by:
Hi all. This is a bit of a long shot i think but right now i am all out of ideas, so any help is greatly appreciated! I have an app that sends information on a specific port. However, te...
2
by: Jan | last post by:
Hello there, I've got a strange problem using the readline method in vb2005 for reading the serial port. If I use the readchar method I can receive one character from serialport. This is the...
4
by: sracherla | last post by:
I am trying to write a simple windows service that accepts an incoming request; receives a string input and sends a string output. I need this connection to stay alive until the client closes it....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.