我使用的是eclipse3.4,jdk6.0编译以下代码为什么通不过,而在jdk5.0上就可以通过,这是为什么?
Server代码如下:import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
public class TankeServer {

private static int ID = 100; 
public static final int TCP_PORT = 8888;
public static final int UDP_PORT = 6666;
List<Client> clients = new ArrayList<Client>();

public void start() {

new Thread(new UDPThread()).start();

ServerSocket ss =null;
try {
ss = new ServerSocket(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
}

while(true) {
Socket s =null;
try {
s = ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
String IP = s.getInetAddress().getHostAddress();
int udpPort = dis.readInt();
Client c = new Client(IP, udpPort);
clients.add(c);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeInt(ID++);
s.close();
System.out.println("A Client Connect! Addr:" + s.getInetAddress() + ":" + s.getPort() + "-----UDP Port:" + udpPort);
} catch(IOException e) {
e.printStackTrace();
}finally{
if(s!=null) {
try {
s.close();
s = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

public static void main(String[] args) {
new TankeServer().start();
} private class Client {
String IP;
int udpPort; 

public Client(String IP, int udpPort) {
this.IP = IP;
this.udpPort = udpPort;
}

}

private class UDPThread implements Runnable {

byte[] buf = new byte[1024];
public void run() {
DatagramSocket ds = null;
 try {
ds = new DatagramSocket(UDP_PORT);
} catch (SocketException e) {
e.printStackTrace();
}
System.out.println("UDP thread started at port:" + UDP_PORT);
while(ds != null) {
 DatagramPacket dp = new DatagramPacket(buf,buf.length);
 try {
ds.receive(dp);
System.out.println("a packet received!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}提示的错误是:java.net.BindException: Address already in use: Cannot bindUDP thread started at port:6666 at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
at java.net.DatagramSocket.bind(DatagramSocket.java:368)
at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
at TankeServer$UDPThread.run(TankeServer.java:80)
at java.lang.Thread.run(Thread.java:619)
 那位大哥能帮帮忙???

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zxsqi521】截止到2008-07-10 17:18:00的历史汇总数据(不包括此帖):
    发帖的总数量:7                        发帖的总分数:80                       每贴平均分数:11                       
    回帖的总数量:13                       得分贴总数量:3                        回帖的得分率:23%                      
    结贴的总数量:7                        结贴的总分数:80                       
    无满意结贴数:3                        无满意结贴分:120                      
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:42.86 %               无满意结分率:150.00%                  
    敬礼!
      

  2.   

    Address already in use,端口被使用。
    在windows的命令行下面,输入:netstat
    可以显示目前正在使用的端口。
      

  3.   

    java.net.BindException: Address already in use: Cannot bindUDP thread started at port:6666
    6666 端口已经被占用