日期:2014-05-20 浏览次数:20837 次
java.net.SocketException: Connection reset by peer: 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 java.io.BufferedOutputStream.flushBuffer(Unknown Source) at java.io.BufferedOutputStream.write(Unknown Source) at java.io.DataOutputStream.writeInt(Unknown Source) at ss.snow.service.ImageSend$Worker.run(ImageSend.java:91)
private class Worker extends Thread { private final int[] data = new int[320 * 240]; private FrameGrabbingControl sendFrame; private Buffer buffer; private BufferToImage image; private BufferedImage sendImage; private ServerSocket ss; private Socket socket; private OutputStream outStream; private boolean isRunning = false; private DataOutputStream dos; @Override public void run() { try { ss = new ServerSocket(8000); } catch (IOException e1) { e1.printStackTrace(); } try { isRunning = true; while (isRunning) { boolean isConnected = false; socket = ss.accept(); outStream = socket.getOutputStream(); System.out.println("有客户端连接"); isConnected = true; while (isConnected) { sendFrame = control; buffer = sendFrame.grabFrame(); image = new BufferToImage((VideoFormat) buffer.getFormat()); sendImage = (BufferedImage) image.createImage(buffer); /* sendImage.getWritableTile(0, 0).getDataElements(0, 0, 320, 240, data); sendImage.releaseWritableTile(0, 0); dos = new DataOutputStream(new BufferedOutputStream(outStream)); for(int i = 0; i < data.length; i++) { dos.writeInt(data[i]); } dos.flush(); */ ImageIO.write(sendImage, "JPEG", outStream); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (outStream != null) { try { outStream.close(); outStream = null; } catch (IOException e) { e.printStackTrace(); } } if (socket != null) { try { socket.close(); socket = null; } catch (IOException e) { e.printStackTrace(); } } if (ss != null) { try { ss.close(); ss = null; } catch (IOException e) { e.printStackTrace(); } } } } }