Java 而客户端线程(套接字)中的循环只输入了两次(android)

Java 而客户端线程(套接字)中的循环只输入了两次(android),java,android,sockets,while-loop,Java,Android,Sockets,While Loop,我正在为Android中的服务器/客户端通信设置一个客户端线程。我可以很好地设置连接。但是当我尝试使用下面的代码循环时,程序只进入while循环两次。(我也试过了,虽然(正确),但什么也没发生…) 我需要线程等待客户端对象更新sendPicture/sendLinks等。。为true发送示例行pw.println(“PICTURE”) 在服务器端(PC),它工作得很好(创建1个用于通信的ServerSocket和其他用于文件传输的ServerSocket) 非常感谢您的帮助 已尝试:while(

我正在为Android中的服务器/客户端通信设置一个客户端线程。我可以很好地设置连接。但是当我尝试使用下面的代码循环时,程序只进入while循环两次。(我也试过了,虽然(正确),但什么也没发生…)

我需要线程等待客户端对象更新sendPicture/sendLinks等。。为true发送示例行pw.println(“PICTURE”)

在服务器端(PC),它工作得很好(创建1个用于通信的ServerSocket和其他用于文件传输的ServerSocket)

非常感谢您的帮助

已尝试:while(true)

实际输出在此停止:

I/--main活动:-------------绑定完成

I/ClientSocketThread:--------------为true---------------------------------------------

I/System.out:有下一行

______________________________行:允许

I/ClientSocketThread:--------------为真------------------------------------------

此方法在等待输入时可能会阻塞

可能是这样

public ClientSocketThread(String ip, int port, MainActivity.myClientSocketThreadHandler h, String message, Client c) {
        this.IP = ip;
        this.message = message;
        this.port = port;
        this.handler = h;
        this.client = c;
        this.clientName = c.getClientName();

    }


    public void run() {
        try {
            clientSocket = new Socket(this.IP, port);
            Scanner is = new Scanner(clientSocket.getInputStream());
            pw = new PrintWriter(clientSocket.getOutputStream(), true);
            String line = "";
            pw.println(message);
            while (!line.equals("OVER")) {

                Log.i("ClientSocketThread", "------------------In true---------------------------------------------");

                if (is.hasNextLine()) {
                    System.out.println("Has next line");
                    line = is.nextLine();
                }else{
                    line = "";
                }

                System.out.println("______________________________Line: " + line);


                /**************************
                 * Connexion établie
                 */
                if (line.equals("PERMITTED")) {


                    Message msg = handler.obtainMessage();
                    msg.what = 1;
                    Bundle bundle = new Bundle();
                    bundle.putString("CONNECTION_NAME", this.connectionName);
                    msg.setData(bundle);
                    handler.sendMessage(msg);
                    client.setConnectionAllowed(true);

                    /**************************
                     * Connexion refusé
                     */
                } else if (line.equals("REFUSED")) {

                    Message msg = handler.obtainMessage();
                    msg.what = 2;
                    Bundle bundle = new Bundle();
                    bundle.putString("CONNECTION_NAME", this.connectionName);
                    msg.setData(bundle);
                    handler.sendMessage(msg);

                    disconnect();
                }


                /**
                 * On veut envoyer une image
                 */
                if (line.startsWith("DSS-PICTURE:")) {

                    System.out.println("Je suis dans le DDS-PICTURE");
                    Integer futurServerPort = Integer.valueOf(line.split(":")[1]);
                    PictureClientSocketThread pictureThread = new PictureClientSocketThread(this.IP, futurServerPort, client.getMyPictureHandler(), "None", client);
                    pictureThread.run();

                }


                if (client.getSendLink() == true) {
                    pw.println("LINK");
                    System.out.println("_______________________________SEND: LINK");
                    client.setSendLink(false);
                }

                if (client.getSendPicture() == true) {
                    pw.println("PICTURE");
                    System.out.println("_______________________________SEND: PICTURE");
                    client.setSendPicture(false);
                }

                if (client.getSendFile() == true) {
                    pw.println("FILE");
                    System.out.println("_______________________________SEND: FILE");
                    client.setSendFile(false);
                }

                if (client.getSendVideo() == true) {
                    pw.println("VIDEO");
                    System.out.println("_______________________________SEND: VIDEO");
                    client.setSendVideo(false);
                }


            }// End while


        } catch (
                Exception e) {
            e.printStackTrace();
        }

    }