WebSockerRails-Android

An Android client of WebSocket-Rails

License

License

Categories

Categories

Net
GroupId

GroupId

br.net.bmobile
ArtifactId

ArtifactId

websocketrails-android
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

WebSockerRails-Android
An Android client of WebSocket-Rails
Project URL

Project URL

https://github.com/ararog/WebSocketRails-Android
Source Code Management

Source Code Management

https://github.com/ararog/WebSocketRails-Android

Download websocketrails-android

How to add to project

<!-- https://jarcasting.com/artifacts/br.net.bmobile/websocketrails-android/ -->
<dependency>
    <groupId>br.net.bmobile</groupId>
    <artifactId>websocketrails-android</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/br.net.bmobile/websocketrails-android/
implementation 'br.net.bmobile:websocketrails-android:1.0.2'
// https://jarcasting.com/artifacts/br.net.bmobile/websocketrails-android/
implementation ("br.net.bmobile:websocketrails-android:1.0.2")
'br.net.bmobile:websocketrails-android:jar:1.0.2'
<dependency org="br.net.bmobile" name="websocketrails-android" rev="1.0.2">
  <artifact name="websocketrails-android" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.net.bmobile', module='websocketrails-android', version='1.0.2')
)
libraryDependencies += "br.net.bmobile" % "websocketrails-android" % "1.0.2"
[br.net.bmobile/websocketrails-android "1.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.3.4
com.koushikdutta.async : androidasync jar 1.3.7
com.google.android : android jar 2.1.2

provided (2)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-annotations jar 2.3.0
com.fasterxml.jackson.core : jackson-core jar 2.3.4

Project Modules

There are no modules declared in this project.

WebSocketsRails client port for Android

Port of JavaScript client provided by https://github.com/websocket-rails/websocket-rails

Built on top of AndroidAsync

Misc

Refer to https://github.com/websocket-rails/websocket-rails to learn more about WebSocketRails

Refer to https://github.com/koush/AndroidAsync to learn more about AndroidAsync

Download

Download the latest JAR or grab via Maven:

<dependency>
    <groupId>br.net.bmobile</groupId>
    <artifactId>websocketrails-android</artifactId>
    <version>(insert latest version)</version>
</dependency>

Gradle:

dependencies {
    compile 'br.net.bmobile:websocketrails-android:1.+'
}

Example

Since data exchange is JSON based, it's strongly recommended to use Jackson API to deserialize data.

Connecting to websocket

private WebSocketRailsDispatcher dispatcher;

...
	try {
		dispatcher = new WebSocketRailsDispatcher(new URL("http://192.168.100.109:3000/websocket"));
		dispatcher.connect();
	} 
	catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
...

Creating and Subscribing a WebSocketRailsChannel

private static WebSocketRailsChannel webSocketRailsChannel;

...

	webSocketRailsChannel = dispatcher.subscribe("chanelName");

...

Trigering a event from WebSocketRailsChannel

private static WebSocketRailsChannel webSocketRailsChannel;

...

	Message message = new Message(); // Create a class with getter and setter as in Jackson API
	
	message.setName("Charles");
	message.setMessage("Hai");
	
	webSocketRailsChannel.trigger("new_message", message);

...

Binding a event to WebSocketRailsChannel

...

	webSocketRailsChannel.bind("new_message", new WebSocketRailsDataCallback() {

		@Override
		public void onDataAvailable(Object data) {
		// Do what you want with the data received.
		
		}
	}

...

Unsubscribing a WebSocketRailsChannel

...

	dispatcher.unSubscribe("chanelName");

...

disconnecting websocket

...
	dispatcher.disconnect();
...

Projects using WebSockerRails-Android

Ow for Android

Versions

Version
1.0.2
1.0.1