Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] WebSocket + Async Read/Write

Hi Joakim,

On Mon, Feb 13, 2012 at 5:14 PM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
WebSocket API is event / frame driven, you don't have access to the raw streams, so you don't have to worry about the blocking / non-blocking nature.

You create a WebSocket implementation object, wire it up to the WebSocketServlet.doWebSocketConnect() and messages (text & binary) and frames are delivered to you.
If you want to write text or buffer arrays to the other side you use the WebSocket.Connection object (passed to you in the onOpen() event) to do that, but those are also in the context of websocket messages.


Imagine your implementing a websocket proxy using some kinda of async websocket client.  When onMessage gets called you call the async websocket client's send method, it might let you know that the write could not complete (perhaps the network is congested). At this point, it would be best if I could as Jetty to suspend calling 'onMessage' until that client write call completes.  When it does complete, I'll un-suspend and that I can continue to proxy more data.

The converse is also handy.  The websocket client will be receiving data from the remote and that I would be sending to jetty to forward on the web browser.  If the connection between jetty and the web browser is slow, I'd rather the thread not get tied up waiting to transmit data.  I'd rather get an indication that the write call did not complete and have some sort of callback when it does complete so that I can resumed proxying more data to it.

--

Hiram Chirino

Software Fellow | FuseSource Corp.

chirino@xxxxxxxxxxxxxx | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo





Back to the top