求教,尝试客户端向服务端发信息,服务端没收到,再发客户端报错?socket write error
public class SocketClient {
public static void main(String[] args) {
SocketClient client = new SocketClient();
client.start();
}
public void start() {
BufferedReader inputReader = null;//收消息
BufferedWriter writer = null;
Socket socket = null;
try {
socket = new Socket("127.0.0.1",9898);
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
inputReader = new BufferedReader(new InputStreamReader(System.in));
String inputContent;
while(!(inputContent = inputReader.readLine()).equals("bye")){
writer.write(inputContent+"\n");
writer.flush();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
writer.close();
inputReader.close();
inputReader.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}