GithubHelp home page GithubHelp logo

bhanditz / engine.io-server-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from koush/engine.io-server-java

0.0 2.0 0.0 1.22 MB

Engine.IO Server Library for Java

Home Page: https://socketio.github.io/engine.io-server-java/

License: MIT License

Shell 0.63% Java 92.93% JavaScript 6.19% HTML 0.25%

engine.io-server-java's Introduction

Engine.IO Java

Build Status codecov

This is the Engine.IO Server Library for Java ported from the JavaScript server.

See also: Engine.IO-client Java

Documentation

Complete documentation can be found here.

Installation

The latest artifact is available on Maven Central.

Maven

Add the following dependency to your pom.xml.

<dependencies>
  <dependency>
    <groupId>io.socket</groupId>
    <artifactId>engine.io-server</artifactId>
    <version>1.2.2</version>
  </dependency>
</dependencies>

Gradle

Add it as a gradle dependency in build.gradle.

compile ('io.socket:engine.io-server:1.2.2')

Engine.IO Protocol 1.x suppport

The current version of engine.io-java does not support protocol 1.x.

Usage

Usage is slightly different based on the server being used.

Create a servlet to handle the HTTP requests as follows:

public class EngineIoServlet extends HttpServlet {

    private final EngineIoServer mEngineIoServer = new EngineIoServer();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
        mEngineIoServer.handleRequest(request, response);
    }
}

Listen for new connections as follows:

EngineIoServer server;  // server instance
server.on("connection", new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        EngineIoSocket socket = (EngineIoSocket) args[0];
        // Do something with socket like store it somewhere
    }
});

Listen for raw packets received as follows:

EngineIoSocket socket;  // socket received in "connection" event

socket.on("packet", new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        Packet packet = (Packet) args[0];
        // Do something with packet.
    }
});

Listen for messages from the remote client as follows:

EngineIoSocket socket;  // socket received in "connection" event

socket.on("message", new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        Object message = args[0];
        // message can be either String or byte[]
        // Do something with message.
    }
});

Send a packet to client as follows:

EngineIoSocket socket;  // socket received in "connection" event

socket.send(new Packet<>(Packet.MESSAGE, "foo"));

WebSockets

Please see the complete documentation on handling WebSockets here.

Features

This library supports all of the features the JS server does, including events, options and upgrading transport.

License

MIT

engine.io-server-java's People

Contributors

trinopoty avatar koush avatar

Watchers

James Cloos 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.