大家好,我正在尝试编写有关客户端和服务器通信的代码。在这里,我在客户端遇到了不幸的错误。并且服务器正在正确监听。所以任何人都通过我的代码,发现任何错误都是错误的。
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();
}