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

后端 未结 2 1359
独厮守ぢ
独厮守ぢ 2021-01-25 18:03

What can go wrong if I simply replace

socket = new Socket()

with

socket = SocketChannel.open().socket()?

Back

2条回答
  •  情话喂你
    2021-01-25 18:26

    There are several.

    1. A Socket acquired via a SocketChannel doesn't appear to support read timeouts.
    2. The InputStream and OutputStream of a socket aren't independent: they have a mutual lock in common.

    Why do you want to interrupt the connect() call? Surely all you want is a connect timeout?

提交回复
热议问题