Git Product home page Git Product logo

socket.io-java-client's Introduction

Build Status

This is a simple porting of socket.io-java-client that allows us to use a maven repository and Google's json parser instead of org.json.JSONObject
In your pom.xml
<!-- in the 'repositories' section -->
<repository>
  <id>keytwo.net</id>
  <name>Keytwo.net Repository</name>
  <url>http://audiobox.keytwo.net</url>
</repository>

<!-- in the 'dependencies' section -->
<dependency>
  <groupId>io.socket</groupId>
  <artifactId>socket.io-client</artifactId>
  <version>0.2.1</version> <!-- the desidered version -->
</dependency>

Flattr this git repo

Socket.IO-Client for Java

socket.io-java-client is an easy to use implementation of socket.io for Java.

It uses Weberknecht as transport backend, but it's easy to write your own transport. See description below. An XHR-Transport is included, too. But it's not functional in its current state.

The API is inspired by java-socket.io.client.

Features:

  • transparent reconnecting - The API cares about re-establishing the connection to the server when the transport is interrupted.
  • easy to use API - implement an interface, instantiate a class - you're done.
  • output buffer - send data while the transport is still connecting. No problem, socket.io-java-client handles that.
  • meaningful exceptions - If something goes wrong, SocketIO tries to throw meaningful exceptions with hints for fixing.

Status: Connecting with Websocket is production ready. XHR is in beta.

How to use

Using socket.io-java-client is quite simple. But lets see:

		SocketIO socket = new SocketIO("http://127.0.0.1:3001/");
		socket.connect(new IOCallback() {
			@Override
			public void onMessage(JSONObject json, IOAcknowledge ack) {
				try {
					System.out.println("Server said:" + json.toString(2));
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onMessage(String data, IOAcknowledge ack) {
				System.out.println("Server said: " + data);
			}

			@Override
			public void onError(SocketIOException socketIOException) {
				System.out.println("an Error occured");
				socketIOException.printStackTrace();
			}

			@Override
			public void onDisconnect() {
				System.out.println("Connection terminated.");
			}

			@Override
			public void onConnect() {
				System.out.println("Connection established");
			}

			@Override
			public void on(String event, IOAcknowledge ack, Object... args) {
				System.out.println("Server triggered event '" + event + "'");
			}
		});

		// This line is cached until the connection is establisched.
		socket.send("Hello Server!");

For further informations, read the Javadoc.

Checkout

  • with git

     git clone git://github.com/Gottox/socket.io-java-client.git
    
  • with mercurial

     hg clone https://bitbucket.org/Gottox/socket.io-java-client
    

Both repositories are synchronized and up to date.

Building

to build a jar-file:

cd $PATH_TO_SOCKETIO_JAVA
ant jar
ls jar/socketio.jar

You'll find the socket.io-jar in jar/socketio.jar

Bugs

Please report any bugs feature requests to the Github issue tracker

Frameworks

This Library was designed with portability in mind.

  • Android is fully supported.
  • JRE is fully supported.
  • GWT does not work at the moment, but a port would be possible.
  • JavaME untested.
  • ... is there anything else out there?

Testing

There comes a JUnit test suite with socket.io-java-client. Currently it's tested with Eclipse.

You need node installed in PATH.

  • open the project with eclipse
  • open tests/io.socket/AllTests.java
  • run it as JUnit4 test.

TODO

  • Socket.io needs more unit-tests.
  • XhrTransport needs to pass all tests.
  • If websockets are failing (due to proxy servers e.g.), use XHR automaticly instead.

License - the boring stuff...

This library is distributed under MIT Licence.

Sounds so interesting...

You'll find further documentation at the Socket.io-java-client Github Wiki

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.