Hii , first sorry if my post in the wrong place , I'm newbie and my English
not good . So , i have project that require to read socket from coldfusion
7 , and I have succeed using standard thread and port listening . Now I'm
try using netty for best speed and response .
This is my listener ,
public class NettyListener {
private final int port;
public NettyListener(int port) {
this.port = port;
}
public void start() throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(group)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch)
throws Exception {
ch.pipeline().addLast(new NettyHandler());
}
}).option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
;
ChannelFuture f = b.bind().sync();
// System.out.println(NettyListener.class.getName()
// + " started and listen on " + f.channel().localAddress());
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully().sync();
}
}
}
and this is my handler
@Sharable
public class NettyHandler extends ChannelInboundHandlerAdapter {
private static String raw;
String inputLine = null;
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf in = (ByteBuf) msg;
inputLine = in.toString(CharsetUtil.UTF_8);
int u = 1;
String lines[] = inputLine.split("[\\r\\n]+");
for (String i : lines) {
if (u == 6) { //this where data place normally
String converT;
converT = i.replace("%20", " ").replace("%2E", ".")
.replace("%2F", "/").replace("%2D", "-")
.replace("%40", "@").replace("%2B", "+")
.replace("%28", "(").replace("%29", ")")
.replace("%2C", ",").replace("%5F", "_");
setRaw(converT);
}
u++;
}
// ctx.write(in);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
{
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(
ChannelFutureListener.CLOSE);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
public static String getRaw() {
return raw;
}
public void setRaw(String raw) {
NettyHandler.raw = raw;
}
}
The problem is when data/message to long, the data will split into 2 object
or more . Is there a way to compact this data/message becoming 1 String
java .
Thank in advance
Regards
Rully
--
You received this message because you are subscribed to the Google Groups
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/netty/c85a9d08-ce66-4e36-8340-2af22aee9897%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.