java.net.ConnectException: Connection refused  
Author Message
Kadir Karaca Ko鏴r





PostPosted: 2004-5-7 0:15:00 Top

java-programmer, java.net.ConnectException: Connection refused Hi,

i have something very strange here:

when i try to connect from my Client (written in Java) my Server (also
in Java) i get SOMETIMES
java.net.ConnectException: Connection refused

1. under Gentoo Linux and localhost:4444 NO EXCEPTION
2. under Knoppix + Debian Linux localhost:4444 NO EXCEPTION
3. windows 2000 localhost:4444 EXCEPTION!
4. all the tree systems IP.of.an.other.PC:4444 EXCEPTION!

Does anybody know why?

Another Client/Server Application (BabylonChat) runs well in any
Configuration!!

Have a nice Day.
Karaca
 
Rob Shepherd





PostPosted: 2004-5-7 0:28:00 Top

java-programmer >> java.net.ConnectException: Connection refused Kadir Karaca Ko鏴r wrote:
> Hi,
>
> i have something very strange here:
>
> when i try to connect from my Client (written in Java) my Server (also
> in Java) i get SOMETIMES
> java.net.ConnectException: Connection refused
>
> 1. under Gentoo Linux and localhost:4444 NO EXCEPTION
> 2. under Knoppix + Debian Linux localhost:4444 NO EXCEPTION
> 3. windows 2000 localhost:4444 EXCEPTION!
> 4. all the tree systems IP.of.an.other.PC:4444 EXCEPTION!
>
> Does anybody know why?
>
> Another Client/Server Application (BabylonChat) runs well in any
> Configuration!!
>
> Have a nice Day.
> Karaca
Windows Firewall software perhaps.
Windows may be blocking port 4444.

Rob
 
Kadir Karaca Ko鏴r





PostPosted: 2004-5-7 0:36:00 Top

java-programmer >> java.net.ConnectException: Connection refused Rob Shepherd wrote:

> Windows Firewall software perhaps.

I don't have a Firewall. *Sorry*

> Windows may be blocking port 4444.

Why? Where can i see/modify this.
Babylon has no problems with port 12468

> Rob
Karaca
 
 
Kadir Karaca Ko鏴r





PostPosted: 2004-5-7 0:43:00 Top

java-programmer >> java.net.ConnectException: Connection refused
>> Windows may be blocking port 4444.

netstat -a says the server is "Listening"
but client says "Connection Refused"

*confused*
Karaca
 
 
Gordon Beaton





PostPosted: 2004-5-7 0:57:00 Top

java-programmer >> java.net.ConnectException: Connection refused On Thu, 06 May 2004 18:15:13 +0200, Kadir Karaca Ko鏴r wrote:
> i have something very strange here:
>
> when i try to connect from my Client (written in Java) my Server (also
> in Java) i get SOMETIMES
> java.net.ConnectException: Connection refused
>
> 1. under Gentoo Linux and localhost:4444 NO EXCEPTION
> 2. under Knoppix + Debian Linux localhost:4444 NO EXCEPTION
> 3. windows 2000 localhost:4444 EXCEPTION!
> 4. all the tree systems IP.of.an.other.PC:4444 EXCEPTION!
>
> Does anybody know why?

Please define "sometimes" with some numbers. Are you trying to connect
often, or only occasionally? Are there many clients, or just one? How
many existing connections are there to the same server when this
occurs?

Do both client and server correctly close all unused Sockets?

What is the (ServerSocket) backlog setting?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
 
Kadir Karaca Ko鏴r





PostPosted: 2004-5-7 19:17:00 Top

java-programmer >> java.net.ConnectException: Connection refused Gordon Beaton wrote:

> Please define "sometimes" with some numbers.

The number are there:
>>1. under Gentoo Linux and localhost:4444 NO EXCEPTION
>>2. under Knoppix + Debian Linux localhost:4444 NO EXCEPTION

---> Linux & Localhost No Problem

>>3. windows 2000 localhost:4444 EXCEPTION!

---> Windows & Localhost does NOT run.

>>4. all the tree systems IP.of.an.other.PC:4444 EXCEPTION!

Every combination of the Computers over LAN --> Connection refused.

> Are you trying to connect
> often, or only occasionally?

It happens evertime when i try to connect. --> I can not connect!

> Are there many clients, or just one? How
> many existing connections are there to the same server when this
> occurs?

One Client. One Connection.
>
> Do both client and server correctly close all unused Sockets?

No connection --> No unused Sockets :-(
>
> What is the (ServerSocket) backlog setting?

Can you please explain it?


Karaca
 
 
Gordon Beaton





PostPosted: 2004-5-7 19:59:00 Top

java-programmer >> java.net.ConnectException: Connection refused On Fri, 07 May 2004 13:16:41 +0200,
=?windows-1254?Q?Kadir_Karaca_Ko=E7er?= wrote:
> It happens evertime when i try to connect. --> I can not connect!

That isn't "sometimes".

Some things to try:

- Show the code where you create the ServerSocket. Which constructor
are you using? Did you bind the ServerSocket to the localhost
address? Dont!
- Show the result of ServerSocket.getInetAddress()
- Show the result of "netstat -a" or "netstat -an" on the server host
- Show the result of "telnet serverhost 4444" from a host where the
client fails to connect.
- Show the result of "traceroute serverhost" from a host where the
client fails to connect.

>> What is the (ServerSocket) backlog setting?
>
> Can you please explain it?

The ServerSocket documentation should show how to set this value,
which represents the number of pending connections (incoming but not
yet accepted) the ServerSocket can handle. It's only relevant if you
are experiencing failures when there are large numbers of clients
attempting to connect at the same time, which doesn't seem to be the
case here.

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
 
Gordon Beaton





PostPosted: 2005-12-8 20:50:00 Top

java-programmer >> java.net.ConnectException: Connection refused On Thu, 08 Dec 2005 13:22:26, Johannes Beekhuizen wrote:
> I'm running mysql 4.1.14, connector/J 3.1.10 and j2sdk 1.5.0.4 under
> SlackWare 10.2. When I try to run the jdbc examples in
> ~/JavaTutorial/jdbc/basics/example-1dot2 I get the following error
> message:

[...]

> java.net.SocketException
> MESSAGE: java.net.ConnectException: Connection refused

The exception says that there is no listening socket at the address
and port number you attempted to connect to.

Is the process running? Is it listening where you think it is? Are you
connecting where you think you are? Most of these things can be
diagnosed with e.g. netstat on the target machine and a network
snooping tool like tcpdump or ethereal.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
 
Johannes Beekhuizen





PostPosted: 2005-12-8 21:22:00 Top

java-programmer >> java.net.ConnectException: Connection refused Hallo All,

I'm running mysql 4.1.14, connector/J 3.1.10 and j2sdk 1.5.0.4 under
SlackWare 10.2. When I try to run the jdbc examples in
~/JavaTutorial/jdbc/basics/example-1dot2 I get the following error
message:

=== import ===
-----SQLException-----
SQLState: 08S01
Message: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused
at
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156 )
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:283)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2541)
at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at BatchUpdate.main(BatchUpdate.java:25)


** END NESTED EXCEPTION **



Last packet sent to the server was 35 ms ago.
Vendor: 0
=== tropmi ===

I *do* have full access to the "coffeebreak" data base from the mysql
client.

Of course I have been reading documentation, but I can not find what
goes wrong. Could somebody help please?

The source code follows and I *have* changed user name and password :)

Groetjes,

Hans.

=== import ===
import java.sql.*;

public class BatchUpdate {

public static void main(String args[]) throws SQLException {

ResultSet rs = null;
PreparedStatement ps = null;

String url = "jdbc:mySubprotocol:myDataSource";

Connection con;
Statement stmt;
try {

Class.forName("myDriver.ClassName");

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {

con = DriverManager.getConnection(url,
"myLogin", "myPassword");
con.setAutoCommit(false);

stmt = con.createStatement();

stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Amaretto', 49, 9.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Hazelnut', 49, 9.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Amaretto_decaf', 49, 10.99, 0, 0)");
stmt.addBatch("INSERT INTO COFFEES " +
"VALUES('Hazelnut_decaf', 49, 10.99, 0, 0)");

int [] updateCounts = stmt.executeBatch();
con.commit();
con.setAutoCommit(true);

ResultSet uprs = stmt.executeQuery("SELECT * FROM
COFFEES");

System.out.println("Table COFFEES after insertion:");
while (uprs.next()) {
String name = uprs.getString("COF_NAME");
int id = uprs.getInt("SUP_ID");
float price = uprs.getFloat("PRICE");
int sales = uprs.getInt("SALES");
int total = uprs.getInt("TOTAL");
System.out.print(name + " " + id + " " +
price);
System.out.println(" " + sales + " " +
total);
}

uprs.close();
stmt.close();
con.close();

} catch(BatchUpdateException b) {
System.err.println("-----BatchUpdateException-----" );
System.err.println("SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
System.err.println("Vendor: " + b.getErrorCode());
System.err.print("Update counts: ");
int [] updateCounts = b.getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
System.err.print(updateCounts[i] + " ");
}
System.err.println("");

} catch(SQLException ex) {
System.err.println("-----SQLException-----");
System.err.println("SQLState: " + ex.getSQLState());
System.err.println("Message: " + ex.getMessage());
System.err.println("Vendor: " + ex.getErrorCode());
}
}
}

=== tropmi ===


 
 
Rhino





PostPosted: 2005-12-8 22:14:00 Top

java-programmer >> java.net.ConnectException: Connection refused
"Johannes Beekhuizen" <email***@***.com> wrote in message
news:email***@***.com...
> Hallo All,
>
> I'm running mysql 4.1.14, connector/J 3.1.10 and j2sdk 1.5.0.4 under
> SlackWare 10.2. When I try to run the jdbc examples in
> ~/JavaTutorial/jdbc/basics/example-1dot2 I get the following error
> message:
>
> === import ===
> -----SQLException-----
> SQLState: 08S01
> Message: Communications link failure due to underlying exception:
>
> ** BEGIN NESTED EXCEPTION **
>
> java.net.SocketException
> MESSAGE: java.net.ConnectException: Connection refused
>
> STACKTRACE:
>
> java.net.SocketException: java.net.ConnectException: Connection refused
> at
> com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156
> )
> at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:283)
> at com.mysql.jdbc.Connection.createNewIO(Connection.java:2541)
> at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
> at
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
> at java.sql.DriverManager.getConnection(DriverManager.java:525)
> at java.sql.DriverManager.getConnection(DriverManager.java:171)
> at BatchUpdate.main(BatchUpdate.java:25)
>
>
> ** END NESTED EXCEPTION **
>
>
>
> Last packet sent to the server was 35 ms ago.
> Vendor: 0
> === tropmi ===
>
> I *do* have full access to the "coffeebreak" data base from the mysql
> client.
>
> Of course I have been reading documentation, but I can not find what
> goes wrong. Could somebody help please?
>
> The source code follows and I *have* changed user name and password :)
>
> Groetjes,
>
> Hans.
>
> === import ===
> import java.sql.*;
>
> public class BatchUpdate {
>
> public static void main(String args[]) throws SQLException {
>
> ResultSet rs = null;
> PreparedStatement ps = null;
>
> String url = "jdbc:mySubprotocol:myDataSource";
>
> Connection con;
> Statement stmt;
> try {
>
> Class.forName("myDriver.ClassName");
>
> } catch(java.lang.ClassNotFoundException e) {
> System.err.print("ClassNotFoundException: ");
> System.err.println(e.getMessage());
> }
>
> try {
>
> con = DriverManager.getConnection(url,
> "myLogin", "myPassword");
> con.setAutoCommit(false);
>
> stmt = con.createStatement();
>
> stmt.addBatch("INSERT INTO COFFEES " +
> "VALUES('Amaretto', 49, 9.99, 0, 0)");
> stmt.addBatch("INSERT INTO COFFEES " +
> "VALUES('Hazelnut', 49, 9.99, 0, 0)");
> stmt.addBatch("INSERT INTO COFFEES " +
> "VALUES('Amaretto_decaf', 49, 10.99, 0,
> 0)");
> stmt.addBatch("INSERT INTO COFFEES " +
> "VALUES('Hazelnut_decaf', 49, 10.99, 0,
> 0)");
>
> int [] updateCounts = stmt.executeBatch();
> con.commit();
> con.setAutoCommit(true);
>
> ResultSet uprs = stmt.executeQuery("SELECT * FROM
> COFFEES");
>
> System.out.println("Table COFFEES after
> insertion:");
> while (uprs.next()) {
> String name = uprs.getString("COF_NAME");
> int id = uprs.getInt("SUP_ID");
> float price = uprs.getFloat("PRICE");
> int sales = uprs.getInt("SALES");
> int total = uprs.getInt("TOTAL");
> System.out.print(name + " " + id + " "
> +
> price);
> System.out.println(" " + sales + " " +
> total);
> }
>
> uprs.close();
> stmt.close();
> con.close();
>
> } catch(BatchUpdateException b) {
> System.err.println("-----BatchUpdateException-----"
> );
> System.err.println("SQLState: " +
> b.getSQLState());
> System.err.println("Message: " + b.getMessage());
> System.err.println("Vendor: " + b.getErrorCode());
> System.err.print("Update counts: ");
> int [] updateCounts = b.getUpdateCounts();
> for (int i = 0; i < updateCounts.length; i++) {
> System.err.print(updateCounts[i] + " ");
> }
> System.err.println("");
>
> } catch(SQLException ex) {
> System.err.println("-----SQLException-----");
> System.err.println("SQLState: " +
> ex.getSQLState());
> System.err.println("Message: " + ex.getMessage());
> System.err.println("Vendor: " +
> ex.getErrorCode());
> }
> }
> }
>
> === tropmi ===
>
>

You say that you have changed the user name and password but did you change
your URL? The value "jdbc:mySubprotocol:myDataSource" is certainly not going
to work. You need "jdbc:mysql:sample" if 'sample' is the name of your
database.

Aside from that, there are many possible obstacles to getting a connection,
many of which Gordon noted in his reply. One obstacle that he didn't mention
is SSH. In my case, I have a Windows client accessing a MySQL database on a
remote server running Linux. The remote server is protected via SSH so I
need to set up an SSH tunnel between the client and server before my client
can connect to the server, otherwise I also get a 'connection refused'
message. Perhaps something like that is causing your problem?

Rhino


 
 
Johannes Beekhuizen





PostPosted: 2005-12-12 20:31:00 Top

java-programmer >> java.net.ConnectException: Connection refused Hallo Rhino,

Op 08 Dec 05 schreef Rhino aan All:

>> I get the following error message:
>> Message: Communications link failure due to underlying exception:

R> You say that you have changed the user name and password but did
R> you change your URL? The value "jdbc:mySubprotocol:myDataSource" is
R> certainly not going to work. You need "jdbc:mysql:sample" if
R> 'sample' is the name of your database.

Yes, sorry, I forgot to mention that in my message. I'm not
*that stupid :))

R> Aside from that, there are many possible obstacles to getting a
R> connection, many of which Gordon noted in his reply. One obstacle that
R> he didn't mention is SSH.

That was no problem in my case, but I'll try to remember this.

Groetjes,

Hans.


 
 
Johannes Beekhuizen





PostPosted: 2005-12-12 20:35:00 Top

java-programmer >> java.net.ConnectException: Connection refused Hallo Gordon,

Op 08 Dec 05 schreef Gordon Beaton aan All:

>> java.net.SocketException
>> MESSAGE: java.net.ConnectException: Connection refused
GB> The exception says that there is no listening socket at the address
GB> and port number you attempted to connect to.

Aha...

GB> Is the process running? Is it listening where you think it is? Are you
GB> connecting where you think you are? Most of these things can be
GB> diagnosed with e.g. netstat on the target machine and a network
GB> snooping tool like tcpdump or ethereal.

It took some effort, but thanks to your information I found what was
wrong: mysqld was started with the --skip-networks. And I learned
something about netstat :) On to the next problem...

Groetjes,

Hans.