Created
August 12, 2011 22:08
-
-
Save jlbfalcao/1143112 to your computer and use it in GitHub Desktop.
SocketChannel problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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