多播接收错误消息

时间:2013-02-20 09:40:51

标签: java multicast

我正在使用MulticastSocket。在AIX 7上使用Websphere 8.0.0.5进行测试。问题是来自发件人的错误消息。测试场景是: 1.运行sendMulticast(新线程) 2.运行receiveMulticast(新线程) 3.运行receiveMulticast(新线程)

第一个接收者线程始终收到正确的消息。辅助接收器线程收到错误的消息。

但有趣的是我在使用Java 6作为控制台应用程序的同一台机器(AIX 7)上尝试了这一点,并且每件事情都可以。

以下是代码:

    static final int port = 9999;
    static final String multicastAddress = "224.2.2.3";


    public static void sendMulticast()  {
        MulticastSocket socket = null;
        DatagramPacket outPacket = null;
        byte[] outBuf;

        long t= System.currentTimeMillis();

        //run 60 seconds
        long end = t+60000;

        try {
            socket = new MulticastSocket();
            String msg;

            while(System.currentTimeMillis() < end) {
                msg = "//172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA";
                outBuf = msg.getBytes();

                InetAddress address = InetAddress.getByName(multicastAddress);
                outPacket = new DatagramPacket(outBuf, outBuf.length, address, port);

                socket.setTimeToLive(32);
                socket.send(outPacket);


                System.out.println("Server sends : " + msg);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                }
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        socket.close();
    }


    public static void receiveMulticast() {
        MulticastSocket socket = null;
        DatagramPacket packet = null;
        byte[] inBuf = new byte[1500];

        long t= System.currentTimeMillis();

        //run 60 seconds
        long end = t+60000;

        try {
            // Prepare to join multicast group
            socket = new MulticastSocket(port);
            InetAddress address = InetAddress.getByName(multicastAddress);
            socket.joinGroup(address);

            while(System.currentTimeMillis() < end) {
                packet = new DatagramPacket(inBuf, inBuf.length);
                socket.receive(packet);
                byte[] payload = packet.getData();
                String msg = new String(payload);
                System.out.println("From " + packet.getAddress() + " Msg : " + msg);
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        socket.close();
    }

这是日志: 您可以在10:39:47:675和10:39:48:177看到丢失的字符串即将到达接收者。

可能是什么问题?

[2/20/13 10:39:45:162 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:45:163 EET] 0000003b SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:45:665 EET] 0000003b SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:45:665 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:46:167 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:46:168 EET] 0000003b SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:46:672 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:46:673 EET] 0000003b SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:47:173 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:47:174 EET] 0000003b SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:47:674 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:47:675 EET] 0000003b SystemOut     O From /46.50.52.50 Msg : CE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA131.242:51860/REFERENCE_DATA
[2/20/13 10:39:47:676 EET] 0000003c SystemOut     O From /172.21.131.242 Msg : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:48:176 EET] 0000003a SystemOut     O Server sends : //172.21.131.242:51860/SERVICE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA
[2/20/13 10:39:48:177 EET] 0000003b SystemOut     O From /46.50.52.50 Msg : CE_EXECUTION_CACHE|//172.21.131.242:51860/ERROR_CODES_CACHE|//172.21.131.242:51860/ACCOUNTING_CACHE|//172.21.131.242:51860/CONFIGURATION_ITEMS_CACHE|//172.21.131.242:51860/REFERENCE_DATA131.242:51860/REFERENCE_DATA

0 个答案:

没有答案