Giter Club home page Giter Club logo

socket.io-server-java's Introduction

Java backend for Socket.IO library (http://socket.io/)

Supports Socket.IO clients version 1.0+ Requires JSR 356-compatible server (tested with Jetty 9 and Tomcat 8)

Right now only websocket and XHR polling transports are implemented.

Based on https://github.com/tadglines/Socket.IO-Java

License: MIT

Websocket endpoint initialization in Jetty

Default websocket endpoint configuration assumes it's located in the root context and accessible via /socket.io/ path.

When Socket.IO backend is integrated into webapp managed by Jetty there is no need to perform additional configuration because Jetty scans for @ServerEndpoint annotation and initializes websocket endpoint automatically.

When Jetty server is embedded into your application, websocket endpoint is located in the root context ("/") and expected to be accessible via /socket.io/ path (default configuration), then in order to initialize endpoint you should add the following code

        WebSocketServerContainerInitializer.
                configureContext(context).
                addEndpoint(WebsocketTransportConnection.class);

When Jetty server is embedded into your application, but websocket endpoint is either located not in the root context ("/") or expected to be accessible via path other than /socket.io/, then in order to initialize endpoint you should add the following code

        ServerContainer serverContainer = WebSocketServerContainerInitializer.
                configureContext(context);
        serverContainer.
                addEndpoint(new AnnotatedServerEndpointConfig(serverContainer,
                        WebsocketTransportConnection.class,
                        WebsocketTransportConnection.class.getAnnotation(ServerEndpoint.class),
                        null) {
                    @Override
                    public String getPath() {
                        return "/"; // context-relative path, "/bar" for context "/foo" and path "/foo/bar"
                    }
                });

See example in com.codeminders.socketio.sample.jetty.ChatServer

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.