Android client / Java server; sending android but not receiving?

I searched for four hours and it drives me crazy. I will try to keep this short if you need more info / code, and I will edit.

So, I have an Android client that connects to the server using PrintWriter and BufferedReader. How it works, it launches a new ASyncTask () to load the connection. When the connection is made, it sends a “Connect” message to the server, and then it loads the listener stream, which has a while loop, waiting for UserInput.readLine ()! = Null, and after it is interrupted, returns a string that starts the process, a function that takes a string and does this action, and restarts the listening task.

 //Listener thread
class listen extends AsyncTask<Integer, Integer, Void> {

    @Override
    protected Void doInBackground(Integer... params) {
        //Disconnect variable that only turned true on backpress
        if (!disconnect) {
            try {
                message = Connection.listen(); //socket object
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // async task finished
        if (!disconnect) {

            say("INCOMMING"); //easy-made function for Toast
            input(message);
        }

    }

}

and in this connection:

public String listen() throws IOException {
    String userInput;

    while ((userInput = in.readLine()) != null) {

    }

    return userInput;
}

Java Java , ArrayList -

:

            while ((inputLine = in.readLine()) != null) {   
                            //Tells HQ to process string, with id being who it coming from
                hq.Process(id, inputLine);
                if (!connected)
                    break;
            }

HQ:

public void Process(int id, String str) {
     String[] msg = str.split(","); //split message
     String send = " "; //string I print to console

     if (msg[0].equals("join")) {
         send = msg[1] + " has joined!";
         parent.seats[cnew.get(id).seat] = id;
         cnew.get(id).sendData();
         System.out.println(id);
     }

, HQ ,

   public void sendData() {
       out.println("chips," + chips); // Update chip count

               //give player his cards
       out.println("card," + hq.parent.gameCards.getCard(10) + ","
               + hq.parent.gameCards.getCard(11));

              //a cry for help to get some output on the phone
       out.println("error,SAY THIS");

      // out.flush(); //commented out because it didn't help at all

       System.out.println("sending id " + id); //debug checker (ignore this)
   }

, , , . , , , Android.

, . ( system.prints). , , . - , , . - , ? ? - ? listen() .

UPDATE: , , while() android, doh, , . . , :

public String listen() throws IOException {
    String userInput;

    while ((userInput = in.readLine()) != null) {
        if (userInput.length() > 2)
            break;
    }

    return userInput;
}

UPDATE: - "" ( quit msg , , out.close rest.close), "MSG" Toast - Toast, . out.close ?

+5
1

, Println - + "\ " . ? ..

+2

All Articles