ローカル アドレスへのソケット チャネルを開く簡単なプログラムを作成しようとしています。このプログラムを実行するたびに接続拒否例外が発生します
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();
}
}
}
私が得る例外は
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)
この問題は、Sun Solaris と HP - UX で発生します。Linux マシンでは問題なく動作するようです。接続が拒否される理由を誰か教えてもらえますか? netstat -a を実行し、ポートが使用されていないことを確認しました。
前もって感謝します!