Why is it showing me that connection has not established? - java

Why java is showing this output for every port connections And is it require any thing like basic frame or package in java other than these.i am working on basic server client program first is client and second is server.I tried basic code for only connection.but it shows this output every time
import java.io.*;
import java.net.*;
class DateClient
{
public static void main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader(new InputStreamReader(soc.getInputStream() ));
System.out.println(in.readLine());
}
}
import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
{
public static void main(String args[]) throws Exception
{
ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date: " + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}
}
THIS IS OUTPUT
output:=
Exception in thread "main" java.net.ConnectException: Connection timed out: conn
ect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at DateClient.main(DateClient.java:8)

You are using the DNS resolver to get the local hostname, and you encounter a timeout when connecting to it, so:
either your DNS resolver is configured to a host that is down or filtered by a firewall,
or the DNS resolver resolves the local host name to an IP that is not the one of your server and is down or filtered by a firewall.
These are the two main cases for which you may have such a timeout, instead of a host unreachable or port unreachable error.
So, replace the line:
Socket soc = new Socket(InetAddress.getLocalHost(),5217);
by this one:
Socket soc = new Socket(InetAddress.getLoopbackAddress(), 5217);
to solve your problem.

Related

Exception in thread "main" java.net.UnknownHostException using RabbitMQ on EC2 Instance Ubuntu rabbitmq

I am running an EC2 Instance RabbitMQ Ubuntu. I have started running the Rabbit MQ on it and it is listening on the public IPv4. I have provided a custom port number 15672, so it is hearing at http://***AWS PUBLIC IP****:15672. Everything is going but, when I am writing java code for both sender and receiver having error at host, which the aws public address and the rabbit mq port as well
Sender error:
Exception in thread "main" java.net.UnknownHostException: http://52.90.84.218:15672
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.rabbitmq.client.DnsRecordIpAddressResolver.resolveIpAddresses(DnsRecordIpAddressResolver.java:83)
at com.rabbitmq.client.DnsRecordIpAddressResolver.getAddresses(DnsRecordIpAddressResolver.java:73)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:56)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:900)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:817)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:954)
at com.demo.Send.main(Send.java:19)
Reciever error:
Exception in thread "main" java.net.UnknownHostException: http://52.90.84.218:15672
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.rabbitmq.client.DnsRecordIpAddressResolver.resolveIpAddresses(DnsRecordIpAddressResolver.java:83)
at com.rabbitmq.client.DnsRecordIpAddressResolver.getAddresses(DnsRecordIpAddressResolver.java:73)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:56)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:900)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:817)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:954)
at com.demo.Recv.main(Recv.java:24)
WHEN I AM using localhost as factory.sethost("localhost");
error as:
[AMQP Connection 127.0.0.1:5672] ERROR com.rabbitmq.client.impl.ForgivingExceptionHandler - An unexpected connection driver error occured
com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 3,1,0,0
at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:170)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:107)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571)
at java.lang.Thread.run(Unknown Source)
[AMQP Connection 0:0:0:0:0:0:0:1:5672] ERROR com.rabbitmq.client.impl.ForgivingExceptionHandler - An unexpected connection driver error occured
com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 3,1,0,0
at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:170)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:107)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571)
at java.lang.Thread.run(Unknown Source)
Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:353)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:900)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:817)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:954)
at com.demo.Recv.main(Recv.java:24)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:372)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:297)
... 7 more
Caused by: com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 3,1,0,0
at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:170)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:107)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571)
at java.lang.Thread.run(Unknown Source)
Let me know where If at all I am going wrong
java code for both sender and receiver:
package com.demo;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
public class Recv {
private final static String QUEUE_NAME = "hello";
public static void main(String[] args) throws IOException, TimeoutException {
// TODO Auto-generated method stub
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
#Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
}
Sender code:
package com.demo;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "hello";
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("http://52.90.84.218:15672");
Connection con = factory.newConnection();
Channel channel = con.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello Santosh";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
con.close();
}
}
UnknownHostException: http://52.90.84.218:15672
implies that you passed a URL to a method that expects a bare hostname or IP address. I.e. the API was expecting just 52.90.84.218 and not a full URL.
Thus where you have
factory.setHost("http://52.90.84.218:15672");
change it to
factory.setHost("52.90.84.218");
factory.setPort(15672);

Connection refused from client to server

I am learning about Sockets in Java and I am only missing how to receive back response from the server.
Following How to send string array object and How to send and receive serialized object in socket channel, I am trying to ask the user to pick as much as he wants out of choices:
1 - 2 - 3 - 4
And then I want to split and send them as an array to a server, where the server should send back the number of choices the user has picked.
For example if the user chose
2 3 4 1 2 3 4 1
Server should return
8
server is sending response fine, but on the client side I get error:
Exception in thread "main" java.net.ConnectException: Connection
refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native
Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown
Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at
java.net.PlainSocketImpl.connect(Unknown Source) at
java.net.SocksSocketImpl.connect(Unknown Source) at
java.net.Socket.connect(Unknown Source) at
java.net.Socket.connect(Unknown Source) at
java.net.Socket.(Unknown Source) at
java.net.Socket.(Unknown Source) at
ClientClass.main(ClientClass.java:26)
I am not sure why the issue. Any help?
My Client:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Scanner;
public class ClientClass {
public static void main(String args[]) throws IOException, ClassNotFoundException
{
// take order and convert it to array of choices
Scanner myScanner = new Scanner(System.in); // take from user
System.out.println("Enter all your choices seperated by space:");
System.out.println("Choices are: 1- 2- 3- 4");
String orderString = myScanner.next();
orderString += myScanner.nextLine();
String orderArray[] = orderString.split(" ");
// send request to server
Socket mySocket = new Socket("127.0.0.1", 4444); // create a socket
ObjectOutputStream out = new ObjectOutputStream(mySocket.getOutputStream());
out.writeObject(orderArray);
// get response from server
InputStream is = mySocket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String message = br.readLine();
System.out.println("Message received from the server : " +message);
}
}
My Server:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.util.Scanner;
public class ServerClass {
public static void main(String args[]) throws IOException, ClassNotFoundException
{
// receive
ServerSocket myServerSocket = new ServerSocket(4444); // create a server socket
Socket mySimpleSocket = myServerSocket.accept(); // accept requests
ObjectInputStream ois = new ObjectInputStream(mySimpleSocket.getInputStream());
String[] choices = (String[]) ois.readObject();
// send back response
OutputStream os = mySimpleSocket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(choices.length);
System.out.println("Message sent to the client is "+choices.length);
bw.flush();
}
}
server is sending response fine
Rubbish. The server isn't even getting an incoming connection, let alone reading the request, let alone sending a response.
but on the client side I get error:
Exception in thread "main" java.net.ConnectException: Connection refused: connect at
On this evidence the server wasn't even running. Certainly not running in the same host as the client, which is what is required by new Socket("127.0.0.1", 4444).

Sending "227 \r\n" on port 21 terminates connection

Let me start off by stating that this is my first post here on stackoverflow. Feel free to point out any mistakes made while posting.
Okay, so the problem at hand is a little weird. I'm currently implementing the FTP protocol for my project, but ran into the following problem. Every time my application has to return the message "227 Entering Passive Mode (<ip1>,<ip2>,<ip3>,<ip4>,<port1>,<port2>)." the connection is terminated. The stack trace being:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at Server$1.run(Server.java:30)
at java.lang.Thread.run(Unknown Source)
In order to replicate the behaviour I decided to build a prototype which accepts a connection on port 21 and sends the message "227 " after recieving an arbitrary message from the client. This also results in the connection being terminated.
(Prototype Code snippet:)
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) {
Thread thread = new Thread(new Runnable() {
public void run() {
ServerSocket server = null;
try {
server = new ServerSocket(21);
} catch (IOException e1) {
e1.printStackTrace();
}
while(true) {
try {
Socket client = server.accept();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line = null;
while((line = reader.readLine()) != null) {
writer.write("227 \r\n");
writer.flush();
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
});
thread.start();
}
}
(I'm aware the above code is not the nicest implementation, but is imho sufficiently adequate for representing the problem at hand.)
After some tinkering with the prototype I have figured out that this behaviour only occurs when sending "227 " in conjunction with using port 21 (e.g. using port 4500 works just fine).
Now of course the obvious workaround to this is to avoid using port 21, but i would like to know why i'm experiencing this. Any input on the matter is highly appreciated ;) (just to make sure, i'm using JavaSE-1.7).

Finding Java server time and client time

I tried this code from this site server client code
It worked perfect on my machine,I first ran the server code then the client code.
And I got the time.
I tried putting the server side code on to another PC and running it on eclipse there,similarly I tried running client side code from eclipse on my side but wasn't successful.
It gave me the following error:
Exception in thread "main" java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at sample.servertime.main(servertime.java:13)
Am I doing it correct or is it wrong what I am doing.Need help.
Here are the 2 codes.
// Date Client
import java.io.*;
import java.net.*;
class DateClient
{
publicstaticvoid main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader(
new InputStreamReader(
soc.getInputStream()
)
);
System.out.println(in.readLine());
}
}
// Date Server
import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
{
publicstaticvoid main(String args[]) throws Exception
{
InetAddress locIP = InetAddress.getByName("192.168.1.21");
ServerSocket s= new ServerSocket(5217, 0, locIP);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date" + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}
}
In the server part you've hard coded the ip address for the server:
InetAddress locIP = InetAddress.getByName("192.168.1.21");
ServerSocket s= new ServerSocket(5217, 0, locIP);
When you run it on the other machine the address will be different and therefore it can't be bound unless you change it.
You could change it to bind to all addresses like:
ServerSocket s = new ServerSocket(5217);
Also, the client will always try to connect to the local machine:
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
So if you want to have the client connect to a server on another machine InetAddress.getLocalHost()has to be changed to the address of the server.

javax.mail.MessagingException: Could not connect to SMTP host?

following is my code to send mail:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public void sendMail(String m_from,String m_to,String m_subject,String m_body){
try {
Session m_Session;
Message m_simpleMessage;
InternetAddress m_fromAddress;
InternetAddress m_toAddress;
Properties m_properties;
m_properties = new Properties();
m_properties.put("mail.smtp.host", "usdc2spam2.slingmedia.com");
m_properties.put("mail.smtp.socketFactory.port", "465");
m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
m_properties.put("mail.smtp.auth", "true");
m_properties.put("mail.smtp.port", "9000");
m_Session=Session.getDefaultInstance(m_properties,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("aaaaa","bbbbb#1"); // username and the password
}
});
m_simpleMessage = new MimeMessage(m_Session);
m_fromAddress = new InternetAddress(m_from);
m_toAddress = new InternetAddress(m_to);
m_simpleMessage.setFrom(m_fromAddress);
m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
m_simpleMessage.setSubject(m_subject);
m_simpleMessage.setContent(m_body, "text/html");
//m_simpleMessage.setContent(m_body,"text/plain");
Transport.send(m_simpleMessage);
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SendMail send_mail = new SendMail();
String empName = "xxxxx";
String title ="<b>Hi !"+empName+"</b>";
send_mail.sendMail("123erft#slingmedia.com", "abz#gmail.com", "Please apply for leave for the following dates", title+"<br>by<br><b>HR<b>");
}
}
but when i run the code it gives me the following exception.
javax.mail.MessagingException: Could not connect to SMTP host: usdc2spam2.slingmedia.com, port: 9000;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at samples.SendMail.sendMail(SendMail.java:46)
at samples.SendMail.main(SendMail.java:55)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
when i ping this usdc2spam2.slingmedia.com it gives me reply without any problem. I am using windows 7
Please help me to resolve this.
This is these two lines which was casting me the problem :
m_properties.put("mail.smtp.socketFactory.port", "465");
m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
and added this line :
m_properties.put("mail.smtp.starttls.enable", "true");
After removing and adding the above lines of code it worked fine.
What causes your problem is right there in the stack trace:
java.net.ConnectException: Connection refused: connect
do you need a password to connect to the SMTP server? Are you sure you are using the right settings (as in port number)? Are you behind a proxy or a firewall? Can you use those settings in a regular mail program (e.g. Thunderbird) and send mails?
This exception usually occurs when there is no service listening on the port you are trying to connect to.
Try to connect using putty or telnet. I can bet you will get the same error.
Verify these things:
Host name and port you're trying to connect to,
The server is listening correctly, and
There's no firewall blocking the connection.
Try to add port 9000 to your inbound rules in your windows firewall.

Categories

Resources