[求助]急!!Address already in use (Exception)
编了开了32个服务器线程, 服务器之间通过某种算法交换数据,每个服务器接受到数据就会开线程处理。 可是我程序运行了2-3分钟就抛出exception了。基本上是说我用完了端口了。用了NETSTAT看了基本好多线程都是TIME-WAIT, 可我明明有关闭socket.服务器:
public static class ListenServer implements Runnable
{
private ServerSocket ss;
...........
public ListenServer(String pot,String lik)
{
。。。。。
try
{
ss=new ServerSocket(sevport,10);
}
catch(IOException ie)
{
System.out.println("can not listen at "+sevport);
ie.printStackTrace();
}
}
public class DialogServer implements Runnable{
Socket s;
String rev;
DataInputStream in;
public DialogServer(Socket sss){
s=sss;
}
public void run(){
try{rev="";
in=new DataInputStream(s.getInputStream());
rev=in.readUTF();
in.close();
s.close();
tempchk+=rev+"$";
}
catch(IOException ie)
{
ie.printStackTrace();
}
}.........
---------------------------------------------------------------
每个子线程处理数据完了发送给特定服务器用的是:
Socket tt = new Socket("localhost", port);
DataOutputStream outt = new DataOutputStream(tt.getOutputStream());
outt.writeUTF(changemsg);
outt.flush();
outt.close();
tt.close();
不是这样关闭socket的吗? 求大家帮帮忙,很急