I'm new to Netty and so far there is a working client-server which can handle String message with StringEncoder and StringDecoder, e.g:
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.TRACE))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(
new LoggingHandler(LogLevel.TRACE),
new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, Delimiters.lineDelimiter()),
new StringEncoder(),
new StringDecoder(),
new ReceiveMessageCommunicatorHandler(localNode, inpeerNodeRegistry, outpeerNodeRegistry));
The input message is just like this: excute_this and server sends back: ok.
Now, what I need to do is a server receives a new text message: get_object, it should send back to any client (e.g: telnet or java application which uses the plain socket) a serialized object as byte array. Then in this client, it can deserialized this object as Java object.
I've known that ObjectEncoder() seems to be the way to do. But, it also serializes the response which should be String to a serialized object while it should do it for some specific messages (e.g: get_object only).
How can I tell Netty when it should encode result as StringEncoder and when should encode as Serialized Object as byte array?