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.
class listen extends AsyncTask<Integer, Integer, Void> {
@Override
protected Void doInBackground(Integer... params) {
if (!disconnect) {
try {
message = Connection.listen();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (!disconnect) {
say("INCOMMING");
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(",");
String send = " ";
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);
out.println("card," + hq.parent.gameCards.getCard(10) + ","
+ hq.parent.gameCards.getCard(11));
out.println("error,SAY THIS");
System.out.println("sending id " + id);
}
, , , .
, , , 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 ?