- public void run() {
- byte[] buffer = new byte[16384];
- DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
- try {
- for (;;) {
- // pool正在关闭(shutdown)时不在接收数据
- if(!pool.isShutdown() && !pool.isTerminated()) {
- mcastSocket.receive(packet);
- pool.execute(new Handler(packet));
- } else {
- LOG.info("JxtaMulticastSocketService is now shutdown.");
- }
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- pool.shutdown();
- }
- }
------------------------------------------------------------------------------------
注意第一行和第二行,每次for循环,都使用同一个buffer,这样当接收数据时,会抛出异常。可以将buffer的声明放在for循环的里面。
——————————————————————————————————
傲轩游戏网
傲轩游戏网