大家好我试图在客户端和服务器通信上编写代码。 在这里,我在客户端得到了不幸的错误。和服务器正在正确收听。所以任何人都要通过我的代码,并发现任何错误是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();
}
答案 0 :(得分:1)
主线程异常不是网络吗?
你不应该在那里做网络。使用Thread,AsyncTask或HandlerThread。