1
我有一个问题,我的网络...的BindException地址已在使用,但使用重用
protected Void doInBackground(Void... arg0) {
int nreq = 1;
System.out.println("Hall000");
try {
ServerSocket sock = new ServerSocket(6677);
sock.setReuseAddress(true);
sock.setSoTimeout(1000);
Socket newsock = sock.accept();
System.out.print("\n");
System.out.println("Creating command...");
System.out.print("\n");
new answercall();
nreq++;
System.out.println(nreq);
final DataInputStream din = new DataInputStream(
ss.getInputStream());
// Einlesen
diny1 = (din).read();
diny2 = (din).read();
diny3 = (din).read();
diny4 = (din).read();
diny5 = (din).read();
diny6 = (din).read();
diny7 = (din).read();
System.out.println("diny" + diny1 + " " + diny2 + " "
+ diny3 + " " + diny4 + " " + diny5 + " " + diny6
+ " " + diny7);
setDiny1(diny1);
setDiny2(diny2);
setDiny3(diny3);
setDiny4(diny4);
setDiny5(diny5);
setDiny6(diny6);
setDiny7(diny7);
System.out.println(diny1 + " " + diny2 + " " + diny3 + " "
+ diny4 + " " + diny5 + " " + diny6 + " " + diny7
+ " " + diny8);
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY1, diny1).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY2, diny2).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY3, diny3).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY4, diny4).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY5, diny5).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY6, diny6).commit();
getSharedPreferences(DINY, MODE_PRIVATE).edit()
.putInt(DINY7, diny7).commit();
} catch (Exception e) {
System.out.println("IO error" + e);
}
return null;
}
logcat的告诉我说:
IO errorjava.net.BindException:绑定失败:EADDRINUSE (地址已经在使用)
我知道它是什么意思,但我不知道,为什么它来...即时使用重用,所以它不应该来,应该吗?我做错了什么?
@MinakoAino当有人编辑你的问题时,你的声望不会降低。如果有人低估了这个问题,它就会减少。如果你的语法和标点粗心,那么对任何试图让你的问题变得更容易理解的人都可能会鼓励人们降低你的评价。 – simonc
也许你是对的....我只是有点愤怒...有人让我的句子完成了其他的意义,比我想要的... btw,你能否请解释一下,sO_REUSEADDR是什么意思?我仍然得到我的例外 –
[套接字手册页](http://www.kernel.org/doc/man-pages/online/pages/man7/socket.7.html)中的SO_REUSEADDR部分给出了一个很好的解释。您可以使用此选项绑定到最近关闭的地址,但不能强制绑定到已具有活动侦听套接字的地址。你有另一个服务器实例已经运行吗? – simonc