无法从组播端口中接收报文
无法从组播端口中接收报文
项目中有一个用到组播的需求,需要在程序中接受服务端发出的组播报文。服务端的组播接口已配置好,可以用客户端上的wireshark抓到udp组播包。
接收报文的代码是用java写的,但是程序执行时却接收不到任何报文,执行到MuticastSocket
的receive
方法时日志中打印了warning,并且线程似乎异常退出了。我不是很清楚究竟是代码的问题还是组播配置的问题,请问是否有人遇到过这种情况,该怎么解决?
问题代码:
//在一个线程中接收组播报文
public void run()
{
MulticastSocket socketR = null;
try{
socketR = new MulticastSocket(8110);
socketR.joinGroup(InetAddress.getByName("233.0.0.7"));
socketR.setReceiveBufferSize(ConstantData.n_BufferSize);
}
catch (Exception e) {
AppLogger.error("失败!", e);
socketR.close();
return;
}
while(true)
{
try
{
byte[] bufferR = new byte[3072];
DatagramPacket dpR = new DatagramPacket(bufferR, bufferR.length);
socketR.receive(dpR); //执行到这里打印warning
...
下面是日志信息,上面的run
接口是在ThreadFrdpNet
这个类里实现的。
10-Dec-2020 06:04:06.094 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/catc]
10-Dec-2020 06:04:06.108 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [catc] appears to have started a thread named [Timer-20] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.util.TimerThread.mainLoop(Timer.java:552)
java.util.TimerThread.run(Timer.java:505)
10-Dec-2020 06:04:06.109 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [catc] appears to have started a thread named [Thread-54] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.net.PlainDatagramSocketImpl.receive0(Native Method)
java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:143)
java.net.DatagramSocket.receive(DatagramSocket.java:812)
thread.ThreadFrdpNet.run(ThreadFrdpNet.java:56)
java.lang.Thread.run(Thread.java:748)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论