Click here to Skip to main content
15,909,747 members
Home / Discussions / Java
   

Java

 
GeneralRe: Java drawString Pin
Richard MacCutchan27-Oct-11 5:45
mveRichard MacCutchan27-Oct-11 5:45 
GeneralRe: Java drawString Pin
Tor Danielsen27-Oct-11 8:08
Tor Danielsen27-Oct-11 8:08 
GeneralRe: Java drawString Pin
phil.o30-Oct-11 23:13
professionalphil.o30-Oct-11 23:13 
QuestionHow to develop server with threads and store in txt file Pin
Member 834295426-Oct-11 4:51
Member 834295426-Oct-11 4:51 
AnswerRe: How to develop server with threads and store in txt file Pin
Richard MacCutchan26-Oct-11 5:06
mveRichard MacCutchan26-Oct-11 5:06 
AnswerRe: How to develop server with threads and store in txt file Pin
jschell26-Oct-11 11:08
jschell26-Oct-11 11:08 
AnswerRe: How to develop server with threads and store in txt file Pin
TorstenH.27-Oct-11 21:44
TorstenH.27-Oct-11 21:44 
QuestionJava NIO connect, Socket.connect - how to detect bad ip address ? Pin
ptomask22-Oct-11 22:57
ptomask22-Oct-11 22:57 
Greetings to all !
I have just begun learning a development in nio sockets. Just wondering why following code does what it does:
Java
SocketChannel sch = SocketChannel.open();
Selector sel = Selector.open();
try {
    sch.configureBlocking(false);
    sch.connect(new InetSocketAddress("0", 80));
    sch.register(sel,SelectionKey.OP_CONNECT);
    sel.select();
    Iterator<SelectionKey> it = sel.selectedKeys().iterator();
    while (it.hasNext()) {
        SelectionKey sk = it.next();
        it.remove();
        if (sk.isConnectable()) {
            System.out.println("Connectable.");
            System.out.println(sch.finishConnect());
            System.out.println(sch.socket().isConnected());
            System.out.println(sch.socket().getInetAddress());
        }
    }
} finally {
    sch.close();
    sel.close();
}


Its output is:
Connectable.
true
true
/0.0.0.0


Which is imho obviously wrong. When I run this classic io code:
Java
Socket s = new Socket();
s.connect(new InetSocketAddress("0", 80));


This also does not crash. But if I run:
Socket s = new Socket("1",1);

It fails with:
Exception in thread "main" java.net.SocketException: Network is unreachable: connect
...

How should I check for errors during connect ?

Thank you and best regards,
Paul
AnswerRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
Richard MacCutchan23-Oct-11 2:15
mveRichard MacCutchan23-Oct-11 2:15 
GeneralRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
ptomask23-Oct-11 2:41
ptomask23-Oct-11 2:41 
GeneralRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
Richard MacCutchan23-Oct-11 2:49
mveRichard MacCutchan23-Oct-11 2:49 
GeneralRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
ptomask23-Oct-11 11:18
ptomask23-Oct-11 11:18 
AnswerRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
Luc Pattyn23-Oct-11 11:54
sitebuilderLuc Pattyn23-Oct-11 11:54 
GeneralRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
Richard MacCutchan23-Oct-11 22:25
mveRichard MacCutchan23-Oct-11 22:25 
GeneralRe: Java NIO connect, Socket.connect - how to detect bad ip address ? Pin
ptomask23-Oct-11 22:49
ptomask23-Oct-11 22:49 
Questionhi, Andrroid app. Pin
gif202020-Oct-11 1:33
gif202020-Oct-11 1:33 
AnswerRe: hi, Andrroid app. Pin
Nagy Vilmos20-Oct-11 1:50
professionalNagy Vilmos20-Oct-11 1:50 
AnswerRe: hi, Andrroid app. Pin
jschell20-Oct-11 8:35
jschell20-Oct-11 8:35 
Questionjava-corba COMM_FAILURE Pin
coco_2819-Oct-11 21:41
coco_2819-Oct-11 21:41 
QuestionGetting last word of a string Pin
Tor Danielsen17-Oct-11 23:11
Tor Danielsen17-Oct-11 23:11 
AnswerRe: Getting last word of a string Pin
Richard MacCutchan17-Oct-11 23:21
mveRichard MacCutchan17-Oct-11 23:21 
AnswerRe: Getting last word of a string Pin
davidshenba17-Oct-11 23:31
davidshenba17-Oct-11 23:31 
AnswerRe: Getting last word of a string Pin
David Skelly18-Oct-11 3:28
David Skelly18-Oct-11 3:28 
AnswerRe: Getting last word of a string Pin
Member 835399113-Nov-11 1:45
Member 835399113-Nov-11 1:45 
QuestionPiccolo with Java Drawing & Positioning Pin
massaslayer14-Oct-11 23:36
massaslayer14-Oct-11 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.