I'm trying to make a simple server-client connection between my phone and my computer, with my phone behaving as a client and sending a typed message to my computer's console.
While the server side is properly functioning, I can't seem to make a socket object in my phone to establish the connection. The client code was copied from my client on my eclipse, it worked perfectly on my PC.
I've searched for a solution for about half an hour but all the answers have either been outdated or too complicated for me.
connect_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
// This is where the error occurs
socket = new Socket(serverAddr, SERVERPORT);
Current_status.setText("Connected");
// Sends output to the socket
out = new DataOutputStream(socket.getOutputStream());
}
catch (UnknownHostException u) {
System.out.println(u);
}
catch (IOException e) {
System.out.println(e);
}
catch (Exception h){
System.out.println("An error has occurred.\n");
}
}
});
I've left a few checkpoints in the code to try to diagnose the issue, and from what I got the problem stems from
socket = new Socket(serverAddr, SERVERPORT);
I read the documentation at https://developer.android.com/reference/java/net/Socket.html#Socket(java.lang.String,%20int) and from what I could get, the only possible error is SecurityException.
All help or clues appreciated.