Git Product home page Git Product logo

icometclient4j's Introduction

iCometClient4j

Android Arsenal

Client of iComet server for Java/Android. iComet server: https://github.com/ideawu/icomet

This project is based the iComet service which can be found in https://github.com/ideawu/icomet created by ideawu(www.ideawu.com).

Simply, this project is an implements of client for iComet service. You can use it in your java project as well as Android project.

If you want to know what the effect of this client is look at, there's an demo in Java prepared for running in none auth mode. Obviously, you need an iComet server. Mine is run on my mac under default configuration.

Demo

There are two demos in this project for Java android Android.

The one for Android is based on the one for Java by using the release jar file. You can find it in https://github.com/ideawu/icomet-demos , where you can also find a updated website demo.

AndroidDemo can be your reference in your own project, but it is suggested that you should implement the logic yourself to match your own business. If there are bugs, please mail me.

Usage

Here's some decription of how to use this client.

Using getInstance() method to get an instance of ICometClient.

Before you connet to the iComet server, you should make the client prepared with the ICometConf object by calling prepare(ICometConf) method. The ICometConf object should be completely initialed with those params which you can find under.

mClient = ICometClient.getInstance();

ICometConf conf = new ICometConf();
conf.host = "127.0.0.1";
conf.port = "8100";
conf.url = "stream";
conf.iConnCallback = new MyConnCallback();
conf.iCometCallback = new MyCometCallback();
conf.channelAllocator = new NoneAuthChannelAllocator();

mClient.prepare(conf);

As you can see, there are one ChannelAllocator and two Callbacks for your business.

The ChannelAllocator is used to connect to your own server and request a channel for connetiong to iComet server and a token for authorization if you need it. Also, seq is configurated in this allocator, such that you can decide whether to fetch some old message of that channel. There is only one method in this interface for now:

allocate();

As their names say, the two Callbacks is used for connection and fetching process separately. It is important that you should always implement these two interface and put them into ICometConf object. Following by a outline of these two Callbacks:

IConnCallback {

	public void onFail(String msg);

	public void onSuccess();

	public void onDisconnect();

	public void onStop();

	public boolean onReconnect(int times);

	public void onReconnectSuccess(int times);
}

ICometCallback {

	public void onDataMsgArrived(Message.Content content);

	public void onMsgArrived(Message msg);

	public void onErrorMsgArrived(Message msg);
	
	public void onMsgFormatError();
}

When the client is ready, just a invoke of connect() method will connect it to iComet server. If you use this client in an Android project, you should invoke this method in an children thread, otherwise you would get a NetworkOnMainThreadException.

Then the IConnCallback will be invoked, if there's nothing wrong, you can use comet() method to listen the connection and you will receive the messages from iCometServer which you can deal with them by ICometCallback.

There's something else to know about the ICometCallback, the onMsgArrived() method will be invoked when any message arrive while onDataMsgArrived() and onErrorMsgArrived() will be invoked on for arriving of specific message related to their name.

Much more information will be in wiki and docs pages soon.

Have fun with it!

icometclient4j's People

Contributors

kyleduo avatar

Watchers

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