I have already been able to connect to the server by the application, receive and display the data sent by it. There are also no problems 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 and print what the server sends:
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 solve this and can help me, I am very grateful.