Merge remote-tracking branch 'Gitee/Develop_Branch' into Develop_Branch
This commit is contained in:
commit
f7d4134fdf
|
@ -10,6 +10,10 @@ server.web.path=/
|
|||
netty.model=true
|
||||
netty.server.port=7070
|
||||
netty.host=
|
||||
# netty±àÂë¸ñʽ
|
||||
netty.encoder=GBK
|
||||
# netty½âÂë¸ñʽ
|
||||
netty.decoder=UTF_8
|
||||
#================================ 邮件=======================================
|
||||
#smtp邮件IP 例:smtp.qq.com
|
||||
mail.smtp.ip=smtp.qq.com
|
||||
|
|
|
@ -21,14 +21,16 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class NettyClient {
|
||||
private static final String NETTY_SERVER_IP= SysConfig.getConfiguration().getProperty("server.web.ip");
|
||||
|
||||
private static final int NETTY_SERVER_PORT=Integer.parseInt(SysConfig.getConfiguration().getProperty("netty.server.port"));
|
||||
private static final String NETTY_ENCODER= SysConfig.getConfiguration().getProperty("netty.encoder");
|
||||
private static final String NETTY_DECODER= SysConfig.getConfiguration().getProperty("netty.decoder");
|
||||
|
||||
protected static Channel channel;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NettyClient.class);
|
||||
|
||||
private static ClientHandler clientHandler;
|
||||
|
||||
public static void start() {
|
||||
EventLoopGroup group = new NioEventLoopGroup();
|
||||
Bootstrap b = new Bootstrap();
|
||||
|
@ -42,8 +44,8 @@ public class NettyClient {
|
|||
ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes());
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
p.addLast(new DelimiterBasedFrameDecoder(1024, delimiter));
|
||||
p.addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
|
||||
p.addLast("encoder", new StringEncoder(Charset.forName("GBK")));
|
||||
p.addLast("decoder", new StringDecoder(charConvert(NETTY_DECODER)));
|
||||
p.addLast("encoder", new StringEncoder(charConvert(NETTY_ENCODER)));
|
||||
p.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
|
||||
p.addLast(clientHandler);
|
||||
}
|
||||
|
@ -68,4 +70,24 @@ public class NettyClient {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Charset charConvert(String strChar){
|
||||
if("utf-8".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.UTF_8;
|
||||
}else if("iso_8859_1".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.ISO_8859_1;
|
||||
}else if("us_ascii".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.US_ASCII;
|
||||
}else if("utf_16".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.UTF_16;
|
||||
}else if("utf_16be".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.UTF_16BE;
|
||||
}else if("utf_16le".equals(strChar.toLowerCase())){
|
||||
return StandardCharsets.UTF_16LE;
|
||||
}else if("gbk".equals(strChar.toLowerCase())){
|
||||
return Charset.forName("GBK");
|
||||
}else{
|
||||
return StandardCharsets.UTF_8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue