apon / lemon Goto Github PK
View Code? Open in Web Editor NEW一个简单、轻量级的Android Socket框架。Android Socket Client Library.
一个简单、轻量级的Android Socket框架。Android Socket Client Library.
这是什么问题啊?
1、乱码
2、一接受消息就断开连接
使用框架时只要一链接成功,没有手动发送指令数,就会一直执行FrameProtocols协议类的方法:
private int getDataLen(InputStream in) throws IOException{
int headLen = 4;
int dataLen;
byte[] pheadBuf = new byte[headLen];
for (int i=0;i<headLen;i++){
int b = in.read();
pheadBuf[i] = (byte) b;
}
dataLen = ByteBuffer.wrap(pheadBuf).getInt()-headLen;
return dataLen;
}
最后长度为-1,就要报异常断开了一直重复链接重复执行:
@OverRide
public byte[] unpack(InputStream inputStream) throws IOException {
DataInputStream dataInputStream = null;
int dataLen = getDataLen(inputStream);
LLog.d(TAG,Thread.currentThread().getName()+": =======解析收到的数据=======:数据大小:"+dataLen);
dataInputStream = new DataInputStream(inputStream);
byte[] buf = null;
if (dataLen > 0) {
if (dataLen > 10 * 1024 * 1024) {
return buf;
}
buf = new byte[dataLen];
dataInputStream.readFully(buf);
}
else {
throw new IOException();//抛出异常断开连接
}
return buf;
}
我是想链接成功之后,手动发送一个App-->设备: 0x55 0xAA 0x06 0x00 0x1D 0x31 0x02 0x06 0x04 0x5D 0X3C
等待返回设备-->App: 0x55 0xAA 0x06 0x00 0x1D 0x31 0x01 0x06 0x04 0X5D 0xCC
怎么定义定制这个协议作者知道?求指导下
最近项目使用了大神的lemon socket框架,但现在遇到一个问题,无法解决,在socket保持通信的状态下(十分钟后也有时候是50分钟后)会的断开,每秒钟都有通信的状态下也会断开,再加上心跳也没解决问题,服务端的socket应该是稳定的,用socket工具测试服务的没发生断开的问题,但我的android socket会断开,有时可以自动重连,有时不行,就直接断了,有没有大神碰到这样情况的?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.