I'm really, really new to Java but do know C and C++. I've a project at work that needs to be written in Java so I'm trying to learn reading both a beginner book and then looking at topics I'm going to need but know nothing about.
I'v been able to use nio selectors (from an example in the Java NIO book) to make an applet which I've modified. I test it by using telnet both at home on my good Mac and at work on my XP notebook. I need to keep track of which machines connect so I decided to use toString(0 to get data on the channel and parse out the IP address and here's what I get in XP:
java.nio.channels.SocketChannel[connected local=/127.0.0.1:6666 remote=/127.0.0.1:4652]
and here's OS-X
java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1%0:6666 remote=/0:0:0:0:0:0:0:1%0:55786]
The IP address from XP is useful but whatever I'm getting from OS-X is not and I wonder what is going on?
Will this be different when I actually have another computer connect rather than use localhost? This project will be done under Linux but I don't have the machines yet. Will different flavors of Linux give different results?
Unless the API clearly specifies the format of the String returned by toStirng() you can't depend on it to be the same between different JVMs. If you need to get info on the SocketChannel's end points, use socket() to retrieve its matching Socket. You can then get the end points from that using getInetAddress() and getLocalAddress(), or getRemoteSocketAddress() and getLocalSocketAddress().