I am trying to send a string from real android device(client) to pc(server) where server is running on Netbeans 8.0 and device is connected to pc over wifi(using pc wifi hotspot by connectify). Server code:
try {
clientSocket = serverSocket.accept(); // accept the client connection
inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); // get the client message
message = bufferedReader.readLine();
System.out.println(message);
inputStreamReader.close();
clientSocket.close();
} catch (IOException ex) {
System.out.println("Problem in message reading");
}
and the client code:
try{
client = new Socket("192.168.207.1", 4444);
printwriter = new PrintWriter(client.getOutputStream(), true);
printwriter.write("SENTTTTTTTTT");
printwriter.flush();
printwriter.close();
client.close();
} catch (Exception e) {Toast.makeText(getApplicationContext(), "Exception-->"+e.getMessage(), Toast.LENGTH_SHORT).show();}
I have tested (Using PING app) that the IP is reachable. But when I ran app on device it gives Exception-->null. But when I tested server & client both on pc as an JAVA SE app it works fine. But it is not working on android device.