public void run()
{

   try 
   {
      while(true)            //代码只执行一次,就退出
     {
       String message = in.readUTF();
        if(message != null)
 {
    for(DataOutputStream o : map)
    {
       o.writeUTF(message);
     }
 }
     }
   
   } 
   catch (IOException e) 
  {
      e.printStackTrace();
  }

解决方案 »

  1.   

    程序并没自动退出。还在循环中。
    只是你第二次in.readUTF();时是处于阻塞状态,
    也就是在继续等待你的输入源。
    有了输入源,才会继续执行下面的for循环,遍历输出流。
      

  2.   

    你可以开2个eclipse,一个运行你的服务端,一个运行你的客户端。
    一直启动服务端,然后客户端发数据过来。
    或者你可以在服务端设断点。
      

  3.   

    加上几个调试信息,就可以看到执行到哪一步了,例如下面这样,猜不太好猜的
        public void run() {
            try  {
                while(true) //代码只执行一次,就退出
                {
                    // 加上调试信息
                    System.out.println("准备读取信息");
                    String message = in.readUTF();
                    System.out.println("读取到信息");
                    if(message != null) {
                        for(DataOutputStream o : map) {
                            System.out.println("输出信息");
                            o.writeUTF(message);
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
      

  4.   

    都是不行
    我发送的代码如下:
    public void actionPerformed(ActionEvent e)
    {
       try
       {
          if(buttonList.peek() != null)
    {
       JButton delButton = buttonList.remove();
       delButton.setIcon(new ImageIcon("img/noone.gif"));
    }
         JButton button = (JButton)e.getSource();
         button.setIcon(RoomPanel.getIcon());
         buttonList.push(button);
     
         int i = list.indexOf(button);
         out.writeUTF(button.getIcon().toString() + "|" + String.valueOf(i) + "|"   +name);
      
       }
       catch (IOException e1) 
       {
    e1.printStackTrace();
       }
      
      
      }
      

  5.   

    我已经写了,知道那里while(true)只执行一次
      

  6.   

    String message = in.readUTF(); 有消息取出来吗?
    是不是在这里因为其他原因阻塞了?
    for(DataOutputStream o : map)
    {
    o.writeUTF(message);
    }把这段屏蔽掉 然后你
    system.out.println(message);
    看看会有什么效果
      

  7.   

    抛出异常了吧?
    try-catch在循环外面