Giter Site home page Giter Site logo

rxwebsocket's Introduction

RxWebSocket 使用步骤 请参考项目demo中的WebSocketManager,可以直接使用,里面的参数配置可自行配置

1. app中build文件依赖

implementation 'io.github.zhou-jun-jie:RxWebSocket:1.0.2'

2. 初始化OkHttpClient

return new OkHttpClient.Builder()
            .connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS)   // 连接超时: 自己定义常量
            .readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)         // 读取超时: 自己定义常量
            .writeTimeout(WRITE_TIME_OUT, TimeUnit.SECONDS)       // 写超时: 自己定义常量
            .pingInterval(PING_INTERVAL, TimeUnit.SECONDS)        // ping的连接时间: 自己定义常量
            .build();

3. 初始化RxWebSocket

rxWebSocket = new RxWebSocketConfig()
            .isPrintLog(true)
            .client(getOkHttpClient())
            .reconnectInterval(RECONNECT_INTERVAL, TimeUnit.SECONDS)
            .build();

4. 注册websocket消息

public void registerWebSocketMsg(String url, long timeout, TimeUnit timeUnit, WebSocketSubscriber<?> webSocketSubscriber) {
    rxWebSocket.get(url, timeout, timeUnit)
            .subscribe(webSocketSubscriber);
}

5. 最后使用

WebSocketManager.getInstance().registerWebSocketMsg(url, new WebSocketSubscriber<String>() {

        @Override
        protected void onMessage(String str) {

        }
    });

rxwebsocket's People

Contributors

zhou-jun-jie avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.