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不停的刷新从服务器读取消息,但是一小段时间后就会报这个错,是什么问题哦?
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不停的刷新从服务器读取消息,但是一小段时间后就会报这个错,是什么问题哦?
解决方案 »
- java读取文件中内容,在线等
- [技术讨论]谈谈Android开发中的Java。
- java 图形操作 GUIjava2D
- java接口问题
- toString方法为什么出现栈溢出,请达人解释一下,越清楚详细彻底越好。谢谢!
- 用JBuilder如何制作表格?在线等,谢谢
- 关于org.apache.commons.net.ftp.FTPClient建立FTP客户端的问题
- 一个windowcloing的问题
- 来帮帮新手吧(大家都来看看呀,帮帮忙)
- 今天顺利通过SCJP考试,高兴!!散分了!!来者有分!!数量有限要快哦!
- 可不可在指定目录下加载class文件
- 高手帮我运行这个APPLET!不能运行!!!!
很明显是端口冲突了,换一个没有被用过的端口就行了
就是说有别的程序在使用8080端口,导致我网页中Applet使用该端口时抛出异常吗?我同一个网页里有两个Applet,一个是聊天室,一个是别的.这两个Applet都在不停的刷新,会不会是这两个Applet之间有冲突呢?不过我记得换用8083端口也会出这个问题
这是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**的那个.一直刷个不停,最后就报错了
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毫秒连接一次服务器,读取消息