如何保持监听一个端口啊?
这样子:ss = new ServerSocket(10000);
while (true)
{
    client = ss.accept();
...
...
}这样运行时客户端可以多次得到服务,但是服务器端的程序界面却全死掉了!
运行时我加一个exit的button用来close socket和exit程序,可是按钮都不能按! 为什么啊!而这样子:服务器端的方法:public void beginListServe() throws IOException
{
ss10000 = new ServerSocket(10000);
client10000 = ss10000.accept();
DataInputStream input = new DataInputStream(client10000.getInputStream());
boolean done = false;
while (!done)
{
//读取客户端发来的list命令   
System.out.println("Reciving...");
String listMsg = input.readUTF();
System.out.println("Recive: "+listMsg);
if (listMsg.equals("BYE"))
done = true;
displayArea.append("A Client Connected!"+"\n");

File file = new File(HpathStr);
String[] fileNames = file.list();
ArrayList fileList = new ArrayList();
//生成文件列表
for (int i=0;i<fileNames.length;i++)
{
if (fileNames[i].contains(".txt"))
fileList.add(fileNames[i]);
}
fileList.add("end"); OutputStream netOut = client10000.getOutputStream();
DataOutputStream output = new DataOutputStream(netOut);
for (int i=0;i<fileList.size();i++)
{
output.writeUTF((String)fileList.get(i));
}
output.flush();
output.close(); 
}
ss10000.close();
client10000.close();
}这是我的客户端方法:
public void connect()throws IOException
{
// connection = new Socket(inputIp.getText(),Integer.parseInt(inputPort.getText()));
connection = new Socket(InetAddress.getLocalHost(),10000);

//向服务器端发送要求文件列表命令"list"
OutputStream netOut = connection.getOutputStream();
DataOutputStream doc = new DataOutputStream(netOut);
doc.writeUTF("list");

DataInputStream input = new DataInputStream(connection.getInputStream());
String fileName = "begin";
ArrayList list = new ArrayList();
while (!fileName.equals("end"))
{
fileName = input.readUTF();
list.add(fileName);
}

//更新服务器端文件列表
String[] array = new String[list.size()];
for (int i=0;i<list.size()-1;i++)
{
array[i] = (String)list.get(i);
}
serverFileList.setListData(array);
this.validate();
connection.close();
}我的要求是服务器端的10000号端口持续监听来自客户端的"list"字符串,如收到则发送所需信息给客户端,而客户端则在需要时发送list命令给服务器断要求传送所需信息
这两个方法运行时,第一次传输正常
而用户第二次运行connect方法要求服务器端传输的时候,客户端就死了!
服务器端死在
String listMsg = input.readUTF();
这里!好像收不到客户端发来的list命令!救急啊1!!!!!!!!!!!!!!!!!!!!!!