You're using non-blocking I/O (in line 10 you're setting it to non-blocking). When you do that, most methods, such as connect() in line 11, return immediately, before the actual connection is made. Setting up the connection happens in a background thread. It's very well possible that when your code reaches line 14, the connection has not yet been set up, so at that point you see that it's not yet connected.
Non-blocking I/O is a specialized and complicated subject. Read the API documentation of methods such as SocketChannel.connect() very carefully - it explains you exactly how those methods behave in case of blocking and non-blocking mode.
I'd advise you to first make a program work with blocking I/O, which is easier to understand. Comment out line 10, or change it to:
If you really want to use non-blocking I/O, you'll have to study how that works exactly first.