Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

无法从组播端口中接收报文

无法从组播端口中接收报文

项目中有一个用到组播的需求,需要在程序中接受服务端发出的组播报文。服务端的组播接口已配置好,可以用客户端上的wireshark抓到udp组播包。

接收报文的代码是用java写的,但是程序执行时却接收不到任何报文,执行到MuticastSocketreceive方法时日志中打印了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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...