Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A


I am trying to run JMS Client and I am getting this exception. I am relatively new but. I made sure through Visula Administrator that my Connection Factories and Queues are there

javax.jms.JMSException: The following hosts (hostname:port) cannot be accessed:

. Check host names and ports.






at QueueSend.main(

Here is the code: Look that the lookup for Queue and Connection Factory was successfull. I am writting standalone java client.

import java.util.Properties;

import javax.naming.*;


import javax.jms.*;

public class QueueSend {

public String uid = null;

public String pass = null;

public QueueSend(String u, String pas) {

this.uid = u;

this.pass = pas;


public static void main (String argv[]) {

System.out.println("MAIN EXECUTING");

Object o = null;

javax.naming.Context ctx = null;

QueueConnectionFactory queueConnectionFactory = null;

QueueConnection queueConnection = null;

QueueSession queueSession = null;

Queue queue = null;

QueueSender queueSender = null;

TextMessage message = null;

try {

System.out.println("IN TRY");

Properties properties = new Properties();





properties.put(Context.SECURITY_CREDENTIALS, "aBcD1234");

properties.put(Context.PROVIDER_URL, "");

System.out.println("ABOUT TO GET CONTEXT");

ctx = new InitialContext(properties);

System.out.println("THE CONTEXT="+ctx);

queueConnectionFactory = (QueueConnectionFactory)ctx.lookup("jmsfactory/default/QueueConnectionFactory");

queue = (Queue) ctx.lookup("jmsqueues/JMS1/SAP_Q1");

queueConnection =


queueSession = queueConnection.createQueueSession(false,


queueSender = queueSession.createSender(queue);

message = queueSession.createTextMessage();


System.out.println("About to Send Message");


System.out.println("Just Send Message");

} catch (Exception e) { e.printStackTrace(); }


private static final boolean sap = false;


  • Create a JNDI InitialContext object


public static Context getContext() {

Context jndiContext = null;

try {

Properties properties = new Properties();

properties.put(Context.PROVIDER_URL, "");





properties.put(Context.SECURITY_CREDENTIALS, "aBcD1234");

jndiContext = new InitialContext(properties);

return (jndiContext);

} catch (NamingException e) {

System.out.println("Could not create JNDI API " +

"context: " + e.toString());



return jndiContext;



Former Member
Former Member replied

Hi Matthew,

When you make a standalone java client the connection will be performed by a TCP socket to the server. Your problem is this cannot be achieved. When you do it from JSP your code will interact directly with the JMS on the server. No opening of socket to itself. That's why it works.

I would suggest launching a visual administrator, then going to the "dispatcher" nodes, (not server) and checking the properties of the JMS_provider service. Set up there a valid TCP port (perhaps it is empty or it is not read ?), then try to restart the whole cluster.

If that will not help you, please open a OSS message where the SAP supoprt guys can help you.



0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question