main website home
  • About this blog

    This blog features updates, opinions, and technical notes from Caucho engineers about Caucho products, the enterprise Java industry, and PHP. Caucho Technology is the creator of the Resin Application Server and the Quercus PHP in Java engine. A leader in Java performance since 1998, Caucho is a Sun JavaEE licensee with over 9000 customers worldwide.
  • Tags

    ajaxworld bam candi cdi cloud cluster comet configuration deploy devoxx eclipse ejb embedded flash flex google app engine hessian hmtp ioc java ee 6 javaone javazone jms messaging newsletter nyjug osgi php pomegranate quercus resin resin 4.0 REST servlet sfjug silicon valley code camp spring testing training tssjs watchdog webbeans web profile websockets wordpress
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
« An Overview of Resin Native Optimizations
Resin Pro Health System now and in the future »

WebSockets in Resin

WebSockets is an IETF specification designed to enable more truly interactive browser applications. It creates a message-based system over TCP, after upgrading from a HTTP request. The messages to and from the browser allow for server-sent events and asynchronous notifications. Think of it as a clean implementation of Comet.

The first applications will likely be simple chat improvements, and will become more sophisticated. Google has already demonstrated a Quake implementation.

Resin’s WebSockets API is designed around streams and messages. Each WebSocket message is a traditional Java stream. The message ends when the stream ends.

Your applications receives messages from a listener, because messages are asynchronous and because Resin wants to save threads when no activity is occurring. When your listener finishes Resin will send the next message:

public interface WebSocketListener { public void onReadBinary(WebSocketContext context, InputStream is) throws IOException; public void onReadText(WebSocketContext context, Reader is) throws IOException; }

You’ll want to read the messages quickly and hand them off, because the next message will wait until you’re done with the current message.

Sending messages is also stream-based. Your application starts a new message with a startBinaryMessage() or startTextMessage() call, writes to the OutputStream or PrintWriter, and closes it when the message completes.

public interface WebSocketContext {
  public OutputStream startBinaryMessage()
    throws IOException;
  public PrintWriter startTextMessage()
    throws IOException;
}

Again, you’ll want to write the message quickly because the next message will wait until the current one finishes.

This entry was posted on Monday, August 22nd, 2011 at 12:59 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.


Caucho Technology is proudly powered by WordPress and Quercus®
Entries (RSS) and Comments (RSS).

  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • BLOG |
  • WIKI 4 |
  • WIKI 3 |
  • Resin: Java Application Server
Copyright (c) 1998-2012 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.
resin® is a cloud optimized, java® application server that supports the java ee webprofile ®