GithubHelp home page GithubHelp logo

jboss-websockets's Introduction

WebSockets for JBoss AS 7.1.2+

NOTE: This does not currently work on versions of AS older than 7.1.2. It also requires use of the Apache Portable Runtime connector (APR). This limitation will be addressed in a future version of AS.

To Configure APR in JBoss AS 7.1.x:

  1. In domain/configuration/domain.xml: Change Line:

      <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">           
    

    to:

      <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="true">
    
  2. Okay, done.

Using the WebsocketServlet:

Once AS 7.1.2+ is configured as specified above, using websockets is as simple as implementing a Servlet which extends org.jboss.as.websockets.servlet.WebsocketServlet and implements its abstract methods. You map the servlet as you normally would, and that servlet mapping will become the upgradable WebSocket path.

Example Implementation:

@WebServlet("/websocket/")
public class MyWebSocketServlet extends WebSocketServlet {

  @Override
  protected void onSocketOpened(WebSocket socket) throws IOException {
    System.out.println("Websocket opened :)");
  }

  @Override
  protected void onSocketClosed(WebSocket socket) throws IOException {
    System.out.println("Websocket closed :(");
  }

  @Override
  protected void onReceivedFrame(WebSocket socket) throws IOException {
    final Frame frame = socket.readFrame();
    if (frame instanceof TextFrame) {
      final String text = ((TextFrame) frame).getText();
      if ("Hello".equals(text)) {
        socket.writeFrame(TextFrame.from("Hey, there!"));
      }
    }
  }
}

Errata:

  1. Message fragmentation is not yet supported.

Known Compatibility

  • Confirmed Working:
  • Chrome 18
  • Firefox 11
  • Safari 5.1
  • MobileSafari on iOS 5.1

Want to Contribute?

Just fork.

jboss-websockets's People

Contributors

mikebrock avatar patriot1burke avatar

Watchers

James Cloos avatar Lucas Holmquist avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.