开发者

What is the difference between write and send on NIO channels?

I'm building a UDP communication system with Java NIO, and browsing through the javadoc for the APIs I noticed that channels have a write primitive and a send primitive. I have p开发者_如何转开发rototyped and tried both, and nothing seems to change in that they both deliver the buffer at the other hand. Similarly, the books I looked at do not seem to help clearing this doubt, so I thought to ask: what is the difference between channel.write and channel.send?

Thanks in advance.


The Javadoc for DatagramChannel.send() tells you the difference

The datagram is transferred from the byte buffer as if by a regular write operation.

This method performs exactly the same security checks as the send method of the DatagramSocket class. That is, if the socket is not connected to a specific remote address and a security manager has been installed then for each datagram sent this method verifies that the target address and port number are permitted by the security manager's checkConnect method. The overhead of this security check can be avoided by first connecting the socket via the connect method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜