局域网中的两台电脑A和B,A发送的数据B能收到,B发送的A却收不到,两台电脑的防火墙都关了,A,B都各自能收到本机发送的数据,两台电脑也能ping通
这是什么问题呢?

解决方案 »

  1.   

    我的代码是
    public class MulticastSender {
     public static void main(String[] args) throws Exception {
    InetAddress group = InetAddress.getByName("230.0.0.1");
    int port = 4000;
            String ip = InetAddress.getLocalHost().getHostAddress();
    MulticastSocket ms = null;
    try{
     ms = new MulticastSocket();
     ms.joinGroup(group);
     while(true) {
       byte[] buffer = ip.getBytes();
       DatagramPacket dp = new DatagramPacket(buffer, buffer.length, group, port);//发送数据包,需要指定发送的网组和端口
        ms.send(dp);
       System.out.println("发送数据包:" + group + ":" + port);
       Thread.sleep(10000);
                       }
       } catch(IOException e) {
           e.printStackTrace();
       } finally {
    if(ms != null) {
      try{
    ms.leaveGroup(group);
    ms.close();
     } catch(IOException e) {}
    }
    } }}public class MulticastReceiver {
    public static void main(String[] args) throws Exception {
    InetAddress group = InetAddress.getByName("230.0.0.1");
    int port = 4000;
    MulticastSocket ms =null;
    String s;


    try{
    ms = new MulticastSocket(port);//创建多播套接字并将其绑定到特定端口
    ms.joinGroup(group);//将此套接字加入到该组

    byte[] buffer = new byte[8192];//分配内存区域
    while(true) {
    DatagramPacket dp = new DatagramPacket(buffer, buffer.length);//创建数据包
    ms.receive(dp);//接收本组内的数据包,并将其存到dp内
    s = new String(dp.getData(), 0, dp.getLength());
    System.out.println(s);
    }
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if(ms != null) {
    try{
    ms.leaveGroup(group);
    ms.close();
    } catch(IOException e) {}
    }
    }

    }}
      

  2.   

    在MulticastReceiver类里加个send函数或打印流...