/* Reference on the received message */
Message receiveMsg = null;
System.out.println("Try to receive the message");
/* Try to receive the message */
receiveMsg = msgConnect.receive();
/* check if we receive a text message */
if ( receiveMsg instanceof TextMessage)
{
TextMessage txtMsg = (TextMessage) receiveMsg;
String receiveTxt = txtMsg.getPayloadText();
System.out.println("Received text : " + receiveTxt);
}
/* Received message wasn't a text one... */
else
{
/* Manage here the message (which wasn't a text one) */
}
/* ******************************************************************************** */
/* RECEIVE A MESSAGE (no blocking way) */
/* ******************************************************************************** */
/* Create a listener class which implement the MessageListener interface */
/* ********************************************************************* */
class myListennerClass implements MessageListener
{
public void notifyIncomingMessage(MessageConnection messageconnection)
{
System.out.println("Message received : ");
Message msg;
try {
/* Get the message */
msg = messageconnection.receive();
/* Check message type */
if (msg instanceof TextMessage )
{
System.out.println(((TextMessage)msg).getPayloadText());
}
else
{
System.out.println("not a text message");
}
} catch (InterruptedIOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/* Create the listener */
MessageListener myListener = new myListennerClass();
msgConnect.setMessageListener(myListener);
} catch (Exception e) {
/* Add here the exception management */
System.out.println("exception : "+ e);
}
/* Wait few minutes in order to receive messages */
Thread.sleep(360000);
I canīt see any obvious problem. The two things I can think about is if the connection string is ill formted or if the program is not having the right permissons.
Bookmarks