Reputation: 7
hi guys im trying to write a code on client and server communication. here im getting unfortunate error in client side. and server is listening correctly. so any one go through my code and find out any error is der.
messsage = textField.getText().toString(); //get the text message on the text field
textField.setText(""); //Reset the text field to blank
try {
client = new Socket("10.0.2.2", 4444); //connect to server
printwriter = new PrintWriter(client.getOutputStream(),true);
printwriter.write(messsage); //write the message to output stream
printwriter.flush();
printwriter.close();
client.close(); //closing the connection
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0
Views: 296
Reputation: 22232
Isn't it network on main thread exception?
You should not be doing network there. Use Thread, AsyncTask or HandlerThread.
Upvotes: 1