Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] WebSocket streaming

I use Jetty 7.5.1 to implement websocket service which makes screen
captures and sends to the client. There is a DiffPicker class which
extends timertask. My WebSocket server side code looks like this:

public class GWWebSocket implements WebSocket.OnTextMessage {

	private Connection connection;

	@Override
	public void onClose(int arg0, String arg1) {
	}

	@Override
	public void onOpen(Connection connection) {
	
		this.connection = connection;
		connection.setMaxIdleTime(10000);
		connection.setMaxTextMessageSize(2*1024);
		connection.setMaxBinaryMessageSize(64*1024);
	}

	@Override
	public void onMessage(String data) {
		Logger.getRootLogger().info("Got message: " + data);

		final int tileSize = 64;
		new DiffPicker(tileSize, new IScreenObserver() {

			@Override
			public void cellChanged(int x, int y, BufferedImage image) {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				try {
					ImageIO.write(image, "png", baos);
					baos.flush();
					byte[] imageInByte = baos.toByteArray();
					baos.close();
					GWResponse response = new GWResponse(imageInByte, x, y);
					
					connection.sendMessage(response.getBytes(), 0,
							response.getSize());		
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}

		}).start(1000, 40);
	}

}

I got the following exception when the client sends a command:

0x0 0x0 0x0 0x84 0x0 0x0 0x0 0xf 0x0 0x0 0x0 0xd java.io.IOException:
closedOut 1000:null
	at org.eclipse.jetty.websocket.WebSocketConnectionD13$WSFrameConnection.sendMessage(WebSocketConnectionD13.java:429)
	at com.logmein.websocket.server.GWWebSocket$1.cellChanged(GWWebSocket.java:49)

What's wrong?


Back to the top