1
I was able to connect to the server through the application, receive and show the data sent by it. There is also no problem sending messages to the server. The problem is: once the connection is established, capture data from an editText and send that data to the server that was opened in Asynctask.
Class I use to open the connection, listen to and print what the server says:
private class ConexaoSocket extends AsyncTask<String, String, Void>{
@Override
protected Void doInBackground(String... args) {
try {
Socket servidor = new Socket("192.168.0.20", 3232);
try {
PrintStream saidaServidor = new PrintStream(servidor.getOutputStream());
Scanner s = new Scanner(servidor.getInputStream());
while (s.hasNextLine()) {
publishProgress(s.nextLine());
}
s.close();
} catch (IOException e) {
e.printStackTrace();
}
servidor.close();
}catch (Exception e){
e.printStackTrace();
System.out.println("Erro: "+e.getMessage());
}
return null;
}
@Override
protected void onProgressUpdate(String... s) {
if(s.length > 0){
txvRetornoSocket.setText(s[0]);
}
}
}
If anyone has any idea how to fix this and can help me, I am most grateful.