日期:2014-05-20 浏览次数:20905 次
byte[] receiveBuf = new byte[BUFSIZE];
byte[] serverInfo = "server send:".getBytes();
for(int i = 0;i < serverInfo.length;i ++){
receiveBuf[i] = serverInfo[i];
}
while(true){
Socket client = serverSocket.accept();
SocketAddress clientAddress = client.getRemoteSocketAddress();
System.out.println("client address:" + clientAddress);
InputStream in = client.getInputStream();
OutputStream out = client.getOutputStream();
while((recvMsgSize = in.read(receiveBuf,serverInfo.length,in.available())) != -1){
out.write(receiveBuf);
}
client.close();
}
Exception in thread "main" java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at TcpEchoServer.main(TcpEchoServer.java:37)