java - Any issues with replacing new Socket() with SocketChannel.open().socket()? -


what can go wrong if replace

socket = new socket() 

with

socket = socketchannel.open().socket()? 

background: have legacy code using new socket(), , wanted able interrupt socket.connect() call. don't want rewrite code use nio. learned thread.interrupt() not interrupt socket.connect(), socket.close() on thread supposed interrupt connection. oddly, worked java 7 not java 6.

i somehow got head using socket = socketchannel().open().socket() magically allow me use thread.interrupt() interrupt socket.connect(). doesn't, oddly, make socket.close() interrupt socket.connect() in java 6 too!

note i'm not directly using attached socketchannel in way---it appears when create socket , never again.

what can go wrong this?

there several.

  1. a socket acquired via socketchannel doesn't appear support read timeouts.
  2. the inputstream , outputstream of socket aren't independent: have mutual lock in common.

why want interrupt connect() call? surely want connect timeout?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -