高频Udp组播发送:过一会儿java.net.SocketException

时间:2019-06-26 13:54:37

标签: java networking udp multicast datagram

我开发了一个应用程序,该应用程序每秒在三个不同的多播UDP地址上发送大约4个数据包,每秒总共发送12个数据包。数据包大小很小,为50个字符的String。一段时间(20分钟)后,所有处理数据包分派的线程都会启动异常:

java.net.SocketException: Invalid argument: no further information
    at sun.nio.ch.DatagramChannelImpl.send0(Native Method)
    at sun.nio.ch.DatagramChannelImpl.sendFromNativeBuffer(DatagramChannelImpl.java:521)
    at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:483)
    at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:462)
    at io.netty.channel.socket.nio.NioDatagramChannel.doWriteMessage(NioDatagramChannel.java:293)
    at io.netty.channel.nio.AbstractNioMessageChannel.doWrite(AbstractNioMessageChannel.java:142)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:939)
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.flush0(AbstractNioChannel.java:360)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.flush(AbstractChannel.java:906)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.flush(DefaultChannelPipeline.java:1370)
    at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:739)
    at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:731)
    at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:717)
    at io.netty.channel.ChannelDuplexHandler.flush(ChannelDuplexHandler.java:117)
    at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:739)
    at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:731)
    at io.netty.channel.AbstractChannelHandlerContext.access$2100(AbstractChannelHandlerContext.java:38)
    at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1139)
    at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1062)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:748)

该应用程序可在Windows 10和JVM 1.8上运行 我怀疑问题与S.O的数据报缓冲区有关。或JVM。有什么想法吗?

1 个答案:

答案 0 :(得分:-1)

已解决。问题与系统操作性UDP端口饱和有关。正确修改了代码,问题得以解决。