I have a Glassfish 3.1.2 server running on a remote machine (JDK 1.6.0\_30). The following code is the stand-alone client running in a Java SE environment, connecting to the JMS using a JNDI lookup. The client is publisher and subscriber at the same time.

I created the JMS connection pool and topic as follows:

```
./asadmin create-jms-resource --restype javax.jms.ConnectionFactory jms/TopicConnectionFactory
./asadmin create-jms-resource --restype javax.jms.Topic jms/TopicUpdate

```

I start two instances of this client. The messages seem to be delivered - no errors - but the messages do not arrive at the subscribers ...

What I am doing wrong ?

Any help appreciated - many thanks in advance! 

```
public class JMS implements MessageListener {

    private TopicConnectionFactory factory;
    private TopicConnection connection;
    private Topic topic;

    private void subscribe() {
        try {
            System.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.6");
            System.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
            InitialContext ctx = new InitialContext();
            factory = (TopicConnectionFactory)ctx.lookup("jms/TopicConnectionFactory");
            topic = (Topic)ctx.lookup("jms/TopicUpdate");
            connection = factory.createTopicConnection();
            TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber subscriber = session.createSubscriber(topic);
            subscriber.setMessageListener(this);
            connection.start();
            while(true) {
                Thread.sleep(5000);
                sendMessage();
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(JMS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NamingException ex) {
            Logger.getLogger(JMS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JMSException ex) {
            Logger.getLogger(JMS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void sendMessage() {
        try {
            TopicSession session = connection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
            TopicPublisher publisher = session.createPublisher(topic);
            TextMessage message = session.createTextMessage();
            message.setText("Message from client.");
            publisher.send(message);
            session.close();
            System.out.println("Message sent.");
        } catch (JMSException ex) {
            Logger.getLogger(JMS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void onMessage(Message msg) {
        System.out.println("Message received.");
    }

    public JMS() {
        subscribe();
    }

    public static void main(String[] args) {
        new JMS();
    }

}

```