socketchannel

Java.nio Channels and TLS

断了今生、忘了曾经 提交于 2019-11-28 06:02:54
How do I secure a Java SocketChannel , ServerSocketChannel or, perhaps even, a DatagramChannel with TLS? I know that there are some frameworks ( #1 #2 ) that advertise to be able, but I want to know if it is possible to achieve this with the pure Java standard library alone. Bruno You need to use the SSLEngine , as documented in Non-blocking I/O with SSLEngine . The libraries you mention use it or use libraries that use it. (Note that this is notoriously difficult to use.) You may find these links interesting: This answer (which also contains a link to a book chapter). Notes from Jean-François

Timeout for SocketChannel doesn't work

只谈情不闲聊 提交于 2019-11-27 15:03:10
I want to use a SocketChannel and to have a timeout for its read/write methods. I've tried to set a timeout for the Socket that owns my SocketChannel like this: channel.socket().setSoTimeout(TIMEOUT); but that doesn't work. Is there any other solution? According to this article , SocketChannel will not timeout for its read operation but you can get this effect from reading from the channel in another way. SocketChannel socketChannel; socketChannel.socket().setSocketTimeout(500); InputStream inStream = socketChannel.socket().getInputStream(); ReadableByteChannel wrappedChannel = Channels

Java.nio Channels and TLS

会有一股神秘感。 提交于 2019-11-27 01:11:15
问题 How do I secure a Java SocketChannel , ServerSocketChannel or, perhaps even, a DatagramChannel with TLS? I know that there are some frameworks (#1 #2) that advertise to be able, but I want to know if it is possible to achieve this with the pure Java standard library alone. 回答1: You need to use the SSLEngine, as documented in Non-blocking I/O with SSLEngine. The libraries you mention use it or use libraries that use it. (Note that this is notoriously difficult to use.) You may find these links

Timeout for SocketChannel doesn't work

混江龙づ霸主 提交于 2019-11-26 16:59:15
问题 I want to use a SocketChannel and to have a timeout for its read/write methods. I've tried to set a timeout for the Socket that owns my SocketChannel like this: channel.socket().setSoTimeout(TIMEOUT); but that doesn't work. Is there any other solution? 回答1: According to this article, SocketChannel will not timeout for its read operation but you can get this effect from reading from the channel in another way. SocketChannel socketChannel; socketChannel.socket().setSocketTimeout(500);