Skip to content

Instantly share code, notes, and snippets.

@jlbfalcao
Created August 12, 2011 22:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlbfalcao/1143112 to your computer and use it in GitHub Desktop.
Save jlbfalcao/1143112 to your computer and use it in GitHub Desktop.
SocketChannel problem
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
public class LeakTest {
public static void main(String[] args) {
new LeakTest().test();
try {
Thread.sleep(1000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void test() {
SocketChannel channel = null;
try {
channel = SocketChannel.open(); // aqui já aparece 'can't identify protocol'
// channel.configureBlocking(false);
final Socket socket = channel.socket();
channel.connect(new InetSocketAddress(InetAddress.getByName("8.8.8.8"), 142));
} catch (IOException e) {
e.printStackTrace();
try {
channel.close();
} catch (Exception f) {
f.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment