├─client 1.0-8

A Socket IO library

License

License

Categories

Categories

Net CLI User Interface
GroupId

GroupId

com.payneteasy.socket-nio
ArtifactId

ArtifactId

client
Last Version

Last Version

1.0-8
Release Date

Release Date

Type

Type

jar
Description

Description

├─client 1.0-8
A Socket IO library

Download client

How to add to project

<!-- https://jarcasting.com/artifacts/com.payneteasy.socket-nio/client/ -->
<dependency>
    <groupId>com.payneteasy.socket-nio</groupId>
    <artifactId>client</artifactId>
    <version>1.0-8</version>
</dependency>
// https://jarcasting.com/artifacts/com.payneteasy.socket-nio/client/
implementation 'com.payneteasy.socket-nio:client:1.0-8'
// https://jarcasting.com/artifacts/com.payneteasy.socket-nio/client/
implementation ("com.payneteasy.socket-nio:client:1.0-8")
'com.payneteasy.socket-nio:client:jar:1.0-8'
<dependency org="com.payneteasy.socket-nio" name="client" rev="1.0-8">
  <artifact name="client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.payneteasy.socket-nio', module='client', version='1.0-8')
)
libraryDependencies += "com.payneteasy.socket-nio" % "client" % "1.0-8"
[com.payneteasy.socket-nio/client "1.0-8"]

Dependencies

compile (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.7
com.google.code.gson : gson jar 2.3.1

test (4)

Group / Artifact Type Version
junit : junit jar 4.4
org.slf4j : slf4j-log4j12 jar 1.7.7
log4j : log4j jar 1.2.14
org.slf4j : jcl-over-slf4j jar 1.7.7

Project Modules

There are no modules declared in this project.

socket-nio

An opensource websocket and socket.io java/android implementation.

Maven Central Build Status Coverage Status

Features

  • small size ( only 50 KBytes )
  • minimum dependencies ( only for logging )
  • small memory footprint
  • GC friendly. We use one permanent buffer for reading messages and do not create new byte arrays for each message
  • Thread-safe without many synchronization points. You can write a message from any thread. A message will be writen to a concurrent queue and then a writer thread pick it up. This is only one synchronization point, other are in a java socket
  • Only two threads: one for reading and another for writing. It is very useful then using the client in an android services
  • https supported via a standart mechanism. We use SSLSocketFactory.createSocket() to create a socket so it is very stable on all android devices
  • production ready. Uses in a messaging application for android existed in Google.Play

How to connect via websocket

WebSocketHandshakeRequest request = new WebSocketHandshakeRequest.Builder()
    .url("http://localhost:8080/socket.io/1/websocket")
    .build();
WebSocketSession session = client.connect(request);

// You can send messages in a separate thread.
// Message will be added to the queue and will be written to the socket in a writer thread.
// So we use only two threads: one for writing messages to a socket and second is for reading from a socket.
// It is very useful in Android to track only two threads.
session.send (...);

// we block a current thread until a connection is closed. 
// It can help you to use only one thread to accept messages from a server.
// Once it done you can rerun it in a loop.
session.startAndWait(new IWebSocketListener() {
    @Override
    public void onMessage(MutableWebSocketFrame aFrame, WebSocketContext aContext) {
        LOG.debug("Frame: {}", aFrame);
    }

    @Override
    public void onFailure(Throwable aError) {
        LOG.error("Failure", aError);
    }
});

How to connect via socket.io

SocketIoClient client = new SocketIoClient();
SocketIoSession session = client.connect(new URL("http://localhost:8080/socket.io/1/");

ISocketIoListener listener = new ISocketIoListener() {

    @Override
    public void onEvent(String aEventName, SocketIoContext aContext, Object... args) {
        LOG.debug("Event is {}", aEventName);
        aContext.ack();
    }

    @Override
    public void onFailure(Throwable aError) {
        LOG.error("Error is", aError);
    }
};

session.startAndWait(listener);

Projects using socket-nio

How to start socket.io server

We use https://github.com/mrniko/netty-socketio to run socket.io server

How to connect to your project

maven

<dependency>
	<groupId>com.payneteasy.socket-nio</groupId>
	<artifactId>client</artifactId>
	<version>1.0-4</version>
</dependency>

gradle

'com.payneteasy.socket-nio:client:1.0-4'

Dependecies

  • com.google.code.findbugs:jsr305:jar
  • org.slf4j:slf4j-api
  • (optional) com.google.code.gson:gson for socket.io

Versions

Version
1.0-8
1.0-7
1.0-6
1.0-4