gpt4 book ai didi

java - BindException Address 已在使用中,但使用重用

转载 作者:行者123 更新时间:2023-11-29 05:49:32 25 4
gpt4 key购买 nike

我的网络有问题...

        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: bind failed: EADDRINUSE (Address already in use)

我知道这是什么意思,但我不知道,为什么会出现...我正在使用重用,所以它不应该出现,对吗?我做错了什么?

最佳答案

来自 ServerSocket 的文档:

The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.

你必须在没有绑定(bind)的情况下创建套接字,设置SO_REUSEADDR 然后绑定(bind):

ServerSocket sock = new ServerSocket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(6677));

PS:当试图阻止他们改进您的问题时,您会尽量减少愿意帮助您的人数。

关于java - BindException Address 已在使用中,但使用重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com