add LengthFieldBasedFrameDecoder
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
dbb95dd999
commit
9d72433199
@ -6,6 +6,11 @@ import java.util.Map;
|
|||||||
* @author ehlxr
|
* @author ehlxr
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
public static final int MAX_FRAME_LENGTH = 1024 * 1024; //最大长度
|
||||||
|
public static final int LENGTH_FIELD_LENGTH = 4; //长度字段所占的字节数
|
||||||
|
public static final int LENGTH_FIELD_OFFSET = 2; //长度偏移
|
||||||
|
public static final int LENGTH_ADJUSTMENT = 0;
|
||||||
|
public static final int INITIAL_BYTES_TO_STRIP = 0;
|
||||||
private static final Map<String, String> SYS_ENV = System.getenv();
|
private static final Map<String, String> SYS_ENV = System.getenv();
|
||||||
public static String SERVER_HOST = "localhost";
|
public static String SERVER_HOST = "localhost";
|
||||||
/**
|
/**
|
||||||
@ -36,22 +41,14 @@ public class Constants {
|
|||||||
* sdk client 默认超时时间
|
* sdk client 默认超时时间
|
||||||
*/
|
*/
|
||||||
public static int SDK_CLIENT_TIMEOUTMILLIS = 2000;
|
public static int SDK_CLIENT_TIMEOUTMILLIS = 2000;
|
||||||
|
/**
|
||||||
|
* 编码解码 byte 数组固定长度
|
||||||
|
*/
|
||||||
|
public static int DECODER_FRAMELENGTH = 100;
|
||||||
private Constants() {
|
private Constants() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEnv(String key) {
|
public static String getEnv(String key) {
|
||||||
return SYS_ENV.get(key) == null ? "" : SYS_ENV.get(key);
|
return SYS_ENV.get(key) == null ? "" : SYS_ENV.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码解码 byte 数组固定长度
|
|
||||||
*/
|
|
||||||
public static int DECODER_FRAMELENGTH = 100;
|
|
||||||
|
|
||||||
public static final int MAX_FRAME_LENGTH = 1024 * 1024; //最大长度
|
|
||||||
public static final int LENGTH_FIELD_LENGTH = 4; //长度字段所占的字节数
|
|
||||||
public static final int LENGTH_FIELD_OFFSET = 2; //长度偏移
|
|
||||||
public static final int LENGTH_ADJUSTMENT = 0;
|
|
||||||
public static final int INITIAL_BYTES_TO_STRIP = 0;
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
package io.github.ehlxr.did.netty;
|
package io.github.ehlxr.did.netty;
|
||||||
|
|
||||||
import io.github.ehlxr.did.netty.MyProtocolBean;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||||
|
@ -92,7 +92,7 @@ public abstract class AbstractClient implements Client {
|
|||||||
logger.debug("write {} to channel", sdkProto);
|
logger.debug("write {} to channel", sdkProto);
|
||||||
|
|
||||||
byte[] bytes = NettyUtil.toBytes(sdkProto);
|
byte[] bytes = NettyUtil.toBytes(sdkProto);
|
||||||
MyProtocolBean myProtocolBean = new MyProtocolBean((byte)0xA, (byte)0xC, bytes.length, bytes);
|
MyProtocolBean myProtocolBean = new MyProtocolBean((byte) 0xA, (byte) 0xC, bytes.length, bytes);
|
||||||
channel.writeAndFlush(myProtocolBean).addListener((ChannelFutureListener) channelFuture -> {
|
channel.writeAndFlush(myProtocolBean).addListener((ChannelFutureListener) channelFuture -> {
|
||||||
if (channelFuture.isSuccess()) {
|
if (channelFuture.isSuccess()) {
|
||||||
//发送成功后立即跳出
|
//发送成功后立即跳出
|
||||||
@ -138,7 +138,7 @@ public abstract class AbstractClient implements Client {
|
|||||||
logger.debug("write {} to channel", sdkProto);
|
logger.debug("write {} to channel", sdkProto);
|
||||||
|
|
||||||
byte[] bytes = NettyUtil.toBytes(sdkProto);
|
byte[] bytes = NettyUtil.toBytes(sdkProto);
|
||||||
MyProtocolBean myProtocolBean = new MyProtocolBean((byte)0xA, (byte)0xC, bytes.length, bytes);
|
MyProtocolBean myProtocolBean = new MyProtocolBean((byte) 0xA, (byte) 0xC, bytes.length, bytes);
|
||||||
channelFuture.channel().writeAndFlush(myProtocolBean).addListener(channelFuture -> {
|
channelFuture.channel().writeAndFlush(myProtocolBean).addListener(channelFuture -> {
|
||||||
if (channelFuture.isSuccess()) {
|
if (channelFuture.isSuccess()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package io.github.ehlxr.did.client;
|
package io.github.ehlxr.did.client;
|
||||||
|
|
||||||
import io.github.ehlxr.did.netty.MyProtocolDecoder;
|
|
||||||
import io.github.ehlxr.did.netty.MyProtocolEncoder;
|
|
||||||
import io.github.ehlxr.did.client.handler.SdkClientHandler;
|
import io.github.ehlxr.did.client.handler.SdkClientHandler;
|
||||||
import io.github.ehlxr.did.common.Constants;
|
import io.github.ehlxr.did.common.Constants;
|
||||||
import io.github.ehlxr.did.common.Try;
|
import io.github.ehlxr.did.common.Try;
|
||||||
|
import io.github.ehlxr.did.netty.MyProtocolDecoder;
|
||||||
|
import io.github.ehlxr.did.netty.MyProtocolEncoder;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package io.github.ehlxr.did.server.sdk;
|
package io.github.ehlxr.did.server.sdk;
|
||||||
|
|
||||||
import io.github.ehlxr.did.common.Constants;
|
import io.github.ehlxr.did.common.Constants;
|
||||||
import io.github.ehlxr.did.netty.MyProtocolBean;
|
|
||||||
import io.github.ehlxr.did.common.NettyUtil;
|
import io.github.ehlxr.did.common.NettyUtil;
|
||||||
import io.github.ehlxr.did.common.SdkProto;
|
import io.github.ehlxr.did.common.SdkProto;
|
||||||
import io.github.ehlxr.did.core.SnowFlake;
|
import io.github.ehlxr.did.core.SnowFlake;
|
||||||
|
import io.github.ehlxr.did.netty.MyProtocolBean;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
Loading…
Reference in New Issue
Block a user