1 Reply Latest reply on Jun 24, 2003 7:29 AM by Adrian Brock

    javax.naming.CommunicationException

    flower_tang Newbie

      I have written a jms program(publisher/subscriber). It can work on the same pc, the publisher can send the message to subscriber successfully. But when i try to work on different pc, i get a error message "javax.naming.CommunicationException [root exception is java.rmi.ConnectionException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refuesed: connect]. How can solve this problem? Which config file should be edited?

      <!--------------- publisher program ------------------------->
      <!-- i try to connect to server (ip addr: 192.168.18.40) -->

      <%@ page import = "javax.naming.Context" %>
      <%@ page import = "javax.naming.InitialContext" %>
      <%@ page import = "javax.naming.NamingException" %>
      <%@ page import = "java.util.Hashtable" %>

      <%@ page import = "javax.jms.TopicConnectionFactory" %>
      <%@ page import = "javax.jms.TopicConnection" %>
      <%@ page import = "javax.jms.TopicSession" %>
      <%@ page import = "javax.jms.TopicPublisher" %>
      <%@ page import = "javax.jms.Topic" %>
      <%@ page import = "javax.jms.TextMessage" %>
      <%@ page import = "javax.jms.Session" %>
      <%@ page import = "javax.jms.JMSException" %>


      Untitled Document
      <meta http-equiv="Content-Type" content="text/html; charset=big5">



      <%
      TopicPublisher topicPublisher;
      TopicConnection topicConnection;
      TopicSession topicSession;
      Topic topic;

      try{
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL,"jnp://192.168.18.40:1099");
      Context context = new InitialContext(env);

      TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup("ConnectionFactory");
      topicConnection = topicFactory.createTopicConnection();
      topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)context.lookup("topic/testTopic");
      topicPublisher = topicSession.createPublisher(topic);

      for (int i = 1; i < 11; i++) {
      String msg = "Hello World no. " + i;
      out.println("Publishing message: " + msg);
      TextMessage message = topicSession.createTextMessage();
      message.setText(msg);

      topicPublisher.publish(topic, message);
      }

      topicSession.close();
      topicConnection.close();
      } catch (NamingException nEx){
      System.out.println(nEx.toString() + "\nDoes the queue exist?");
      //System.exit(1);
      }

      %>




      Thanks a lot!!!