I am writing server-client app using Netty 4.1.9.
Recently I successfully made communication using ByteBuf. Then tried with String and succeed again.
But with last step I wanted to send custom Object and there is my problem:
Send failed: java.lang.UnsupportedOperationException: unsupported message type: GIdPacket (expected: ByteBuf, FileRegion)
Some code parts
Server:
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
ch.pipeline().addLast(new ObjectEncoder());
ch.pipeline().addLast(new ServerHandler());
ch.pipeline().addLast(loggingHandler);
}
})
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.AUTO_READ, true);
ChannelFuture f = b.bind(port).sync();
ServerHandler:
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception
{
System.out.println("CHANNEL >> channelActive fired");
clientData = new ClientData(Server.newId(), ctx.channel());
Server.clients.put(clientData.id, clientData);
GIdPacket packet = new GIdPacket(/*some init atr*/);
ChannelFuture cf = ctx.writeAndFlush(packet);
if (!cf.isSuccess()) {
System.out.println("Send failed: " + cf.cause());
}
Log.out(packet.toString());
}
So, I tried many different options. I spent much time on that and I didn't found solution. Any help appreciated.