Git Product home page Git Product logo

oksocket's Introduction

OkSocket Document

An blocking socket client for Java application or Andorid.

License Download Download
Open source licenses Basic Socket Library Socket Server Plugin Library

中文在线文档

OkEchoServer Open Source

  • Because the echo server already out of service.ofcause online server is not working properly, we decided to open source, hoping let more people who need point-to-point, mobile-to-mobile communication to get more help.

OkEchoServer Source

OkSocket Introduce

OkSocket is a Java library project designed to solve lightweight Socket communication, in order to enable developers to focus more on business logic, rather than TCP communication principles and some protocols. Make Socket communication more beautiful, suitable for large, medium and small Project, the rapid development of stable, maintainable, reliable Socket connection.

Feature

  • SocketClient Tcp IPV4 Connect
  • Socket Standard Protocol
  • SocketClient Reconnect
  • SocketClient Heartbeat
  • Socket Sticky Unpacking
  • Socket SSL Socket Support
  • Client Callback In Thread / Main Thread
  • Socket Client Redirect
  • SocketServer Support

Instructions

  • OkSocket instruction manual WIKI

  • Add the following configuration to the build.gradle file under the project project.

allprojects {
    repositories {
        jcenter()
    }
}
  • Make sure you have already done with put JCenter into repositories blocking in project Gradle files than you need add the following configuration to the module's build.gradle file.
dependencies {
	//Basic Socket client functionality
	api 'com.tonystark.android:socket:latest.release'
	//If you want to use server functionality, you need to compile the following libraries
	api 'com.tonystark.android:socket-server:latest.release'
}

Policy

   Copyright [2018] [徐昊]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

oksocket's People

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  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  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  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oksocket's Issues

异常断开:com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb,cause=com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb

往服务端发送一个json数据,接收服务端返回的数据报了这个错误。。。!异常断开:com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb,cause=com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb

we can't read data bigger than

com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb
这个是什么错误啊?我的数据不超过3KB

大神,你好

你写的oksockect还是挺好用的,但是有时候会手机锁屏后会碰到onSocketWriteResponse方法一直不停调用的情况出现,我自己没有去发送Socket,而且心跳也没那么频繁,最后的结果是手机ANR 了,请问你又碰到这样的情况吗?

你好,麻烦看一下

com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb,cause=com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb

这个问题 我发现 跟 那个 BIG_ENDIAN 和 LITTLE_ENDIAN 有关系,这个东西高低字节有点不太好理解!
而且 我发现不管是发心跳 还是做别的处理操作,都没有特别详细的说明!!
希望作者可以在努力优化一下!!!

另外还出现一个问题
E/Socket: Socket服务器连接成功 211.154.132.85:7709
E/libGLESv2: HWUI Protection: wrong call f
E/Socket: write bytes: 60 00 00 00 1e 2b 4
E/Socket: bytes write length:96
E/RDS: onSocketWriteResponse 96
E/Socket: read head: 53 00 00 00
E/Socket: need read body length: 83

读取包的时候 已经发现 正确的 body 有83个字节了.
这个时候 就一直停在这里等.. 大约1分钟 后 出现以下问题

E/Socket: read total length:83
E/Socket: read head: 1c 27 ff ff
E/Socket: need read body length: -55524
E/Socket: duplex read error,thread is dead with exception:com.xuhao.android.libsocket.impl.exceptions.ReadException: this socket input stream has some problem,wrong body length -55524,we'll disconnect
E/Socket: duplex_read_thread is shutting down
E/RDS: onSocketReadResponse
E/RDS: data ==长度 ==== 83
E/RDS: data == 协议号 15003

不知道 是什么情况造成的,,,希望作者大大 能解答一下! 这只是连接 socket 做一个登陆操作而已,都走不下去了,, 后续的接口更无法进行下去了.... 感觉很尴尬!

求助

文件和图片传输的话怎么改源码呀。。。。

频繁发消息报异常。

频繁的发 1
duplex read error,thread is dead with exception:com.xuhao.android.libsocket.impl.exceptions.ReadException: this socket input stream has some problem,wrong body length -1,we'll disconnect

发送较大数据时,无法保持心跳?

你好!首先非常感谢你的开源框架,对我帮助很大!现在我遇到了一些问题,就是我需要向服务端发送base64的图片数据,数据量较大,在心跳保持时间过后还没有传完数据,导致服务端关闭了socket连接。请问能有什么办法解决吗?

appcompat_v7包

看了下你的appcompat_v7:26.1.0这个版本包,我从Manager SDK 去下载也下载不了26.1.0的v7包

您好,请问报这个错怎么解决呢。

com.xuhao.android.libsocket.impl.exceptions.ReadException: com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: at com.xuhao.android.libsocket.impl.blockio.io.ReaderImpl.read(ReaderImpl.java:111)
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: at com.xuhao.android.libsocket.impl.blockio.threads.DuplexReadThread.runInLoopThread(DuplexReadThread.java:35)
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: at com.xuhao.android.libsocket.impl.LoopThread.run(LoopThread.java:50)
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: at java.lang.Thread.run(Thread.java:818)
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: Caused by: com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: at com.xuhao.android.libsocket.impl.blockio.io.ReaderImpl.read(ReaderImpl.java:63)
03-22 16:59:59.000 2832-2929/com.blx.blxevdetector W/System.err: ... 3 more

非常抱歉 这两天没有看您的回复.

很抱歉 这两天因为个人原因没有查看您的回复, 他是通过Socket发送给我1024x1280长度的数据,也就是一帧照片的数据, 但是他给我发送数据的时候是发送了两条数据,一条3个字节的,另一条为1024x1280.其中三个字节的数据是我发给服务器获取照片的指令,他捕获到返回给我,并且再发送一条1024x1280的数据.我做数据接收的时候,是直接写3个字节的包头,1024x1280的包体么,我不太了解Socket的通信机制

解析服务器返回的数据的一点疑问

您好大神,很清新的一个socket框架!火钳刘明!
我在看README的时候看到解析服务器返回的数据是set一个自定义的IHeaderProtocol,在getHeaderLength中返回包头的长度。在getBodyLength返回数据的长度,但是getBodyLength的方法参数只是(byte[] header, ByteOrder byteOrder),我没明白如何通过这两个参数获取到包体的长度。是需要我在其他地方获取或者保存整个消息体的长度?还是说服务器在包头中给我把包体的长度包含进去?亦或是其他方法?

manager.disconnect无效

在onDestory里面调用disconnect,重新打开应用的时候,再次链接会多次触发onSocketConnectionSuccess,这个怎么解决

与网络调试助手连接

可以连接上 但是网络调试助手发一个 “1”过来都会报错:Caused by: com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb

断开重连

好像没有因为断开网络后,自动重连机制?
比如,因连接失败后,自动间矩几秒后,自动重新连接

请问如何处理Read超时问题

加入在通讯过程中数据丢包,或者服务器端发送的body数据短于header中定义的长度,造成inputstream.read()进入无限等待状态,我尝试mSocket.setSoTimeout(5000),但无法达到预想的效果,连接超过5秒后,连接自动断开了。我期望是每次执行read有一个超时时间可以设置,请问有什么好的解决方法?

作者你好,使用okSocket发生java.nio.BufferOverflowException 异常问题

作者大大 你好, 最近发现在使用的时候 发生缓冲 异常问题: 不知道应该怎么解决,来请教一下!
com.xuhao.android.libsocket.impl.exceptions.ReadException: java.nio.BufferOverflowException
at com.xuhao.android.libsocket.impl.blockio.io.Reader.read(Reader.java:105)
at com.xuhao.android.libsocket.impl.blockio.threads.DuplexReadThread.runInLoopThread(DuplexReadThread.java:35)
at com.xuhao.android.libsocket.impl.LoopThread.run(LoopThread.java:50)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.nio.BufferOverflowException
at java.nio.Buffer.checkPutBounds(Buffer.java:183)
at java.nio.ByteArrayBuffer.put(ByteArrayBuffer.java:266)
at com.xuhao.android.libsocket.impl.blockio.io.Reader.readBodyFromChannel(Reader.java:126)
at com.xuhao.android.libsocket.impl.blockio.io.Reader.read(Reader.java:94)

关于多个socket在后台的存活时间问题

你好,请问下使用OkSocket.open()得到多个connectionManager,对每个connectionManager设置不同的OkSocketOptions.mBackgroundLiveMinute,即在后台的存活时间,查看了下EnvironmentalManager类的mHandler的处理,发现是对所有的connectionManager进行disConnect的处理,即使每个connectionManager的mBackgroundLiveMinute不同,请问下这样处理的原因是什么呢?

我们自定义协议设置了头和尾,但是用了你的代码返回了超过10m了

int bodyLength = headerProtocol.getBodyLength(originalData.getHeadBytes(), mOkOptions.getReadByteOrder()); 直接提示超过10m 我们的头是[top] 尾[end]
我用你的
okOptionsBuilder.setHeaderProtocol(new IHeaderProtocol() {
@OverRide
public int getHeaderLength() {
//Returns a custom header length that automatically parses the length of the head
return "[top]".getBytes().length;
}

        @Override
        public int getBodyLength(byte[] header, ByteOrder byteOrder) {
            //The length of the body is parsed from the header, byteOrder is the sequence of bytes that you configured in the parameter, which can be easily parsed using ByteBuffer
            if (header == null || header.length == 0) {
                return 0;
            }
            if (ByteOrder.BIG_ENDIAN.toString().equals(byteOrder.toString())) {
                return BytesUtils.bytesToInt2(header, 0);
            } else {
                return BytesUtils.bytesToInt(header, 0);
            }
        }
    });

直接报异常了 我应该怎么设置啊 提示返回超过10m 也就几个字节 怎么可能超过10m

作者你好,接上面发文

刚修改了一下 你的接收的源码. 在得到了 body 长度的时候 减去包头 4字节的长度后
就可以正常运行,,

offline ?

Hi Thanx for this library.
can i use this lib for internal chat or data transferring like xender (Wifi socket Connection Client-Server)?

建议加入header的检查和下跳

建议在自定义协议中加入头部数据的检查,能在getbodylength前处理,丢弃或保留header的部分数据(header中可能未读取或者已包含了body的数据),如果不做容错处理,若对方因干扰传入了不符合协议的数据后面读取就乱套了。

Some permissions required is unnecessary and useless in this library

There are three permissions I questioned:

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>

As a socket library, it needn't get user accounts, read profile or contacts. In this library, these permissions are required but useless.

Maybe you can remove them from README.md and README-CN.md .

能修改包头的数据类型吗?

。。。老大,请问,我公司的服务端包头定位为Varint类型的,所以无法正常读取包头,如果有源码修改就好了

包体长度怎么解析?

@OverRide
public int getBodyLength(byte[] header, ByteOrder byteOrder) {
//从header(包头数据)中解析出包体的长度,byteOrder是你在参配中配置的字节序,可以使用ByteBuffer比较方便解析
return 0;
}
这个包体长度到底怎么解析,能不能告知下方法,比如我现在 header 数据是 {0,1,0,1, 0,0,0,106},后面4位表示包体的长度。

OOM

12-22 17:47:44.725 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 772255(31MB) AllocSpace objects, 1(68KB) LOS objects, 0% free, 27MB/27MB, paused 943us total 117.273ms
12-22 17:47:45.190 13929-13941/com.dsh.client I/art: Background partial concurrent mark sweep GC freed 1036731(40MB) AllocSpace objects, 0(0B) LOS objects, 12% free, 29MB/33MB, paused 942us total 157.429ms
12-22 17:47:45.718 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 1244577(48MB) AllocSpace objects, 0(0B) LOS objects, 7% free, 30MB/33MB, paused 1.189ms total 189.730ms
12-22 17:47:46.230 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 1238303(48MB) AllocSpace objects, 0(0B) LOS objects, 8% free, 30MB/33MB, paused 1.016ms total 188.813ms
12-22 17:47:46.707 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 1184767(46MB) AllocSpace objects, 0(0B) LOS objects, 9% free, 30MB/33MB, paused 966us total 152.452ms
12-22 17:47:47.187 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 1184742(46MB) AllocSpace objects, 0(0B) LOS objects, 9% free, 30MB/33MB, paused 903us total 154.748ms
12-22 17:47:47.701 13929-13941/com.dsh.client I/art: Background sticky concurrent mark sweep GC freed 1189576(46MB) AllocSpace objects, 0(0B) LOS objects, 8% free, 30MB/33MB, paused 963us total 173.634ms
viewpager 数据请求导致OOM 这个怎么解决 大佬

数据传输 - 延迟

大佬 传输数据时 频率快,然后每次传输数据较大的时候会有延时...我server用的是demo...这个有什么建议吗?

项目导入报错

Error:(6, 0) Gradle DSL method not found: 'google()',请问你的studio是3.0以上版本吗?

数据问题.

您好,我现在的使用场景是连接一台wifi相机,通过Socket连接后,点击app中的拍摄,相机会发送一段数据到我的app,发送一个16位数3个字节.然后继续发一个10241280的照片数据.
按照您readme中提示,我自定义了包头长度3,包体1024
1280,每次拍摄后的包头数据都不一致,所以现在我有点不清楚该怎么做.

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.