Skip to main content

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

Hi,

2011/9/28 István Bender <istvan.bender@xxxxxxxxx>:
> 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?

The WebSocket connection has been closed while your DiffPicker was
waiting to trigger. When it triggered, the connection was already
closed.
The close code 1000 indicates that this is a normal close (called by
application code).
You should check if your application is closing websocket connections,
or if the client did it.

Simon
-- 
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

Back to the top