java.net.BindException: Address already in use: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.<init>(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
        at scene.URLOpWatcher.run(URLOpWatcher.java:50)一个Applet不停的刷新从服务器读取消息,但是一小段时间后就会报这个错,是什么问题哦?

解决方案 »

  1.   

    你使用的端口号已经被别的应用程序使用了,如果你想查看是哪个应用程序占用了你想使用的端口号的话,可以使用Active Ports这个软件来查看你的电脑上所有的运行程序目前已经使用的端口号
      

  2.   

    java.net.BindException: Address already in use: connect
    很明显是端口冲突了,换一个没有被用过的端口就行了
      

  3.   

    用dos环境的netstat看端口的使用情况就好了
      

  4.   

    先谢谢几位!我用的8080端口,登陆页面的地址是http://localhost:8080/webcva/login.jsp
    就是说有别的程序在使用8080端口,导致我网页中Applet使用该端口时抛出异常吗?我同一个网页里有两个Applet,一个是聊天室,一个是别的.这两个Applet都在不停的刷新,会不会是这两个Applet之间有冲突呢?不过我记得换用8083端口也会出这个问题
      

  5.   

    刚才用ActivePorts看了一下,我的程序运行起来后,端口使用好像是不停的增加?我不是很懂..
    这是Aports输出的清单:
    Unknown 0 127.0.0.1 3928 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3927 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3926 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3925 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3924 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3923 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3920 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3919 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3916 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3911 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3910 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3909 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3908 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3907 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3906 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3903 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3902 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3898 127.0.0.1 8080 TIME_WAIT TCP
    Unknown 0 127.0.0.1 3897 127.0.0.1 8080 TIME_WAIT TCP
    ....................
    有个LocalPort 一直在变化,就是上表中39**的那个.一直刷个不停,最后就报错了
      

  6.   

    贴上我的代码吧,用于刷新的那个类.高手帮我看看啊!马上要毕业了,遇到这个头痛的问题...
    package scene;import java.io.*;
    import java.net.*;
    import scene.*;
    import scene.javabeans.*;
    import java.util.*;
    import javax.media.j3d.*;
    import javax.vecmath.Matrix4d;
    import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;public class URLOpWatcher
        extends Thread {
      private static int SLEEP_TIME = 20;  private SceneApplet client;
      private String ID;
      private String server;  public URLOpWatcher(SceneApplet c, String ID, String server) {
        System.out.println("New OPWacher!");    this.client = c;
        this.ID = ID;
        this.server = server;
      }  public void run() {
        System.out.println("OpWatcher Run!");    URL url;
        URLConnection conn;
        Operation response;    String readRequest = null;
        try {
          readRequest = server + "?cmd=read&ID=" +
              URLEncoder.encode(ID, "UTF-8");
          System.out.println(readRequest);
          while (true) {
            Thread.sleep(SLEEP_TIME);        url = new URL(readRequest); // send a "read" message        System.out.println("URLOpWatcher OpenConnection!");
            conn = url.openConnection();
            conn.setDoInput(true);
            conn.connect();        InputStream is = conn.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            System.out.println(ois.toString());        MyArrayList responseArray = (MyArrayList) ois.readObject();
            
            for (int i = 0; i < responseArray.size(); i++) {
              response = (Operation) (responseArray.get(i));
              System.out.println(response == null);
              String opType = response.getOpType();
              System.out.println(opType);
    .................
    catch (Exception ex) {
          client.jTF_showInfo.append("Watching terminated!Thread stopped!\n");
          client.jTF_showInfo.append(ex.getLocalizedMessage()+"\n");
          client.jTF_showInfo.append(ex.getMessage()+"\n");
          client.jTF_showInfo.append(ex.toString()+"\n");
          ex.printStackTrace();
        }
      }
    }每隔20毫秒连接一次服务器,读取消息