Java UDP 服务器,并发客户端

问题描述:

下面的代码是否足以接受并发 UDP 传输?更具体地说,如果 2 个客户端同时传输,DatagramSocket 会在我调用 receive() 时将传输排队并一一传递,还是只有一个通过?

Is the code below sufficient to accept concurrent UDP transmissions? More specifically, if 2 clients transmit concurrently, will DatagramSocket queue up the transmissions and deliver them one by one as I call receive(), or will only one make it through?

DatagramSocket socket = new DatagramSocket(port, address);
byte[] buffer = new byte[8192];

while(!disconnect){

    DatagramPacket p = new DatagramPacket(buffer, buffer.length);
    socket.receive(p);
}

默认没有排队.客户端可能会重试,直到超时或达到类似情况.UDP 速度很快,但在负载较重时,您可能会遇到无法连接的客户端.

There is no queuing by default. The client may retry till timeout or similiar are reach. UDP is quiet fast but on heavy load you may have clients that cannot connect.