Communication between the socket of my java application andorid (client) and my java pc (server) application does not work.
I have 2 java applications, one for mobile and another for computer. It is assumed that the andorid application (client) should send a message to the computer (server) and that the computer should display it by console.
When I do it from another computer application if it sends the message, but putting the same code in the application for android does not send it and I do not know why. I have to say that when it worked for me the two applications were on the same computer.
The error that the Andorid app shows me when I send a text is:
scoket failed: EACCES (Permission denied)
This is the code of the application for Andorid (Client) where I have the socket defined.
public void BontonEnviar(View view) {
try {
Socket miSocket = new Socket("192.168.100.190",9999);
DataOutputStream flujoSalida = new DataOutputStream(miSocket.getOutputStream());
String mensaje = elementoEntrada.getText().toString();
flujoSalida.writeUTF(mensaje);
flujoSalida.close();
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
elementoSalida.setText(e1.getMessage());
}
}
This is the code of the application for PC (Server) where I have defined the socket:
@Override
public void run() {
try {
ServerSocket servidor = new ServerSocket(9999);
Socket miSocket = servidor.accept();
DataInputStream flujoEntrada = new DataInputStream(miSocket.getInputStream());
String mensaje = flujoEntrada.readUTF();
areatexto.append("\n"+mensaje);
miSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
This is the code of the application for PC (Client) where if I have worked the sending of data between applications:
@Override
public void actionPerformed(ActionEvent e) {
try {
Socket miSocket = new Socket("192.168.100.190",9999);
DataOutputStream flujoSalida = new DataOutputStream(miSocket.getOutputStream());
flujoSalida.writeUTF(campo1.getText());
flujoSalida.close();
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
System.out.println(e1.getMessage());
}
}