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

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.

An example (a simple echo websocket) is here.
https://github.com/jetty-project/jetty-autobahn-websocket-webapp/blob/master/src/main/java/org/eclipse/jetty/test/WebSocketEchoServlet.java

--
Joakim Erdfelt
joakim@xxxxxxxxxxx

http://webtide.com | http://intalio.com
(the people behind jetty and cometd)



On Mon, Feb 13, 2012 at 2:44 PM, Hiram Chirino <hiram@xxxxxxxxxxxxxxxx> wrote:
Hi Jesse,

I don't see in that example where either socket reading is suspended or socket writing is non-blocking.  How about this question, which apis should I use to:

* suspend socket reads
* resume read
* do a non-blocking write and how do I know when the write completes (so I can resume doing more writes).

On Mon, Feb 13, 2012 at 4:35 PM, Jesse McConnell <jesse.mcconnell@xxxxxxxxx> wrote:
I suspect the best easily accessible example would be something in cometd, guessing http://svn.cometd.org/trunk/cometd-java/cometd-websocket-jetty/

cheers,
jesse

--
jesse mcconnell
jesse.mcconnell@xxxxxxxxx



On Mon, Feb 13, 2012 at 14:41, Hiram Chirino <hiram@xxxxxxxxxxxxxxxx> wrote:
So is there an example?


On Mon, Feb 13, 2012 at 3:24 PM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
WebSocket read/write on the server side is done within the context of the jetty IO framework, and is async if you use the NIO http connectors on jetty.
It is a bit influenced, however, by how proper the websocket framing is from the client, a bad/incomplete frame has in some edge cases (websocket extensions) can cause limited blocking (but those bugs are being squashed as we discover them)

--
Joakim Erdfelt

(the people behind jetty and cometd)



On Mon, Feb 13, 2012 at 1:17 PM, Hiram Chirino <hiram@xxxxxxxxxxxxxxxx> wrote:
Hi are there any examples of how to use the Jetty websocket APIs with async reads and writes.  Specifically, I'd like to suspend/resume socket reading and I'd like be able to do non-blocking writes.

--

Hiram Chirino

Software Fellow | FuseSource Corp.

chirino@xxxxxxxxxxxxxx | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo





_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev



_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev




--

Hiram Chirino

Software Fellow | FuseSource Corp.

chirino@xxxxxxxxxxxxxx | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo





_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev



_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev




--

Hiram Chirino

Software Fellow | FuseSource Corp.

chirino@xxxxxxxxxxxxxx | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo





_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev



Back to the top