1

我的网络有问题...

        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 错误java.net.BindException:绑定失败:EADDRINUSE(地址已在使用中)

我知道这意味着什么,但我不知道,它为什么来...我正在使用重用,所以它不应该来,不是吗?我做错了什么?

4

1 回答 1

3

从以下文档ServerSocket

未定义套接字绑定后启用或禁用 SO_REUSEADDR 时的行为(参见 isBound())。

您必须在没有绑定的情况下创建套接字,SO_REUSEADDR然后设置和绑定:

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

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

于 2013-01-22T11:52:58.233 回答