Ich versuche, ein einfaches Programm zu schreiben, um einen Socket-Kanal zu einer lokalen Adresse zu öffnen. Ich erhalte eine Verbindung Ausnahme verweigert, wenn ich dieses Programm ausführenjava.net.ConnectException: Verbindung abgelehnt, wenn SocketChannel.open aufgerufen wird
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
public class testSocket {
public static void main(String [] args) {
try {
InetAddress addr = InetAddress.getByName("localhost");
InetSocketAddress remoteAddress = new InetSocketAddress(addr, 19015);
// Open a new Socket channel and set it to non-blocking
SocketChannel socketChannel = SocketChannel.open();
socketChannel.configureBlocking(false);
// Issue the Connect call on the remote address.
socketChannel.connect(remoteAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Die Ausnahme, die ich erhalte, ist
java.net.ConnectException: Connection refused
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:464)
at testSocket.main(testSocket.java:17)
ich mit Sun Solaris und HP dieses Problem auftritt - UX. Es scheint auf einem Linux-Rechner gut zu funktionieren. Kann mir jemand mitteilen, warum die Verbindung verweigert wird? Ich habe einen netstat -a gemacht und bestätigt, dass der Port nicht benutzt wird.
Vielen Dank im Voraus!