This file contains 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
/*Java NIO中的DatagramChannel是一个能收发UDP包的通道。因为UDP是无连接的网络协议,所以不能像其它通道那样读取和写入。它发送和接收的是数据包。*/ | |
public static void reveive(){ | |
DatagramChannel channel = null; | |
try{ | |
channel = DatagramChannel.open(); | |
channel.socket().bind(new InetSocketAddress(8888)); | |
ByteBuffer buf = ByteBuffer.allocate(1024); | |
buf.clear(); | |
channel.receive(buf); | |