Code Monkey home page Code Monkey logo

rxsocket's Introduction

Socket连接-RxSocket

功能简介

  • 服务器断开、网络错误等各种方式导致连接失败都会自动一直重连上服务器。
  • 心跳反馈,设置一个时间,每隔一个时间向服务器发送数据,保持在线。

使用方式(Android端)

Android端扫码下载体验

RxSocket.png

1.初始化RxSocket

PS.此项目使用Rx2

//初始化
RxSocket rxSocket = RxSocket.getInstance();

2.重连机制连接

/**
* 重连机制的订阅
* 参数1:服务器地址
* 参数2:端口号
*/
rxSocket.reconnection(HOST, PORT)
        .subscribe(s -> Log.d("server response data", s));

3.心跳重连机制连接(不可动态改变心跳数据)

/**
* 心跳、重连机制的订阅
* 参数1:服务器地址
* 参数2:端口号
* 参数3:心跳发送时间
* 参数4:心跳发送信息
*/
rxSocket.reconnectionAndHeartBeat(HOST, PORT, 5, "---Hello---")
        .subscribe(s -> Log.d("server response data", s));

4.心跳重连机制连接(可动态改变心跳数据)

动态改变心跳数据主要针对于,比如电量cpu内存温度等情况需要动态设置心跳数据。

/**
* 心跳、重连机制的订阅(心跳数据动态改变)
* 参数1:服务器地址
* 参数2:端口号
* 参数3:心跳发送时间
*/
rxSocket.reconnectionAndHeartBeat(HOST, PORT, 5)
	.flatMap(aLong -> mRxSocket.send(mEtHeartText.getText().toString()))
        .compose(mRxSocket.<String>heartBeatChange())
        .subscribe(s -> Log.d("server response data", s));

5.发送数据

mSubscribe = rxSocket.send("hello").subscribe()

6.应用退出或者不需要socket取消订阅

//取消订阅
mSubscribe.dispose();

使用方式(服务端)

使用此软件就不用自己写服务器,先模拟自己测试完毕再跟服务器联调。 服务端模拟软件下载(仅支持Windows系统) 按照图片标注设置就行了。测试是否接收到数据能否发送数据就行了。

网络调试助手.png

意见反馈

如果遇到问题或者好的建议,请反馈到:issue、[email protected] 或者[email protected]

如果觉得对你有用的话,赞一下吧!

rxsocket's People

Contributors

liangludev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rxsocket's Issues

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.