I made a simple Netty Server. It receives requests from clients, read 
information from database and send it back to the client. The server send 
back "the answer" in JSON format. The problem is that the JSON object 
sometimes bigger than 15-20 MB. The server convert the object to JSON 
format correctly, but the client doesn't get the whole information. 
I always get the exception on the client side:
com.google.gson.JsonSyntaxException: com.google.gson.stream.
MalformedJsonException: Unterminated string at line 1 column 44021 path $.
The problem is that bufferedreader only reads the first 44020 characters of 
the response. (However the response is much bigger.)
Somebody can help me what is the problem with my code?

My initializer class:
    protected void initChannel(SocketChannel c) throws Exception {
        ChannelPipeline pipeline = c.pipeline();
        pipeline.addLast(new StringDecoder(Charset.forName("UTF-8")));
        pipeline.addLast(new StringEncoder(Charset.forName("UTF-8")));

        pipeline.addLast("handler", new ServerHandler(p2p));

Server.java sendMessage method:
    private void sendMessage(ChannelHandlerContext ctx, Message msg, 
boolean closeConnection) {
        String msgJson = gson.toJson(msg) + "\r\n";
        ChannelFuture future = ctx.writeAndFlush(msgJson);
        if (closeConnection) {

Client.java sendRequestMessage
public Message sendRequestMessage(Message msg) throws Exception {
        Peer peer = getPeer();

        Socket newClientSocket = new Socket(peer.getHost(), peer.getPort());
        InputStream bounded = new 
BoundedInputStream(newClientSocket.getInputStream(), MAX_FRAME_SIZE);
        BufferedReader reader = new BufferedReader(new 
        PrintWriter writer = new 

        //Send request Message
        writer.print(gson.toJson(msg, Message.class) + "\r\n");

        String response = reader.readLine();
        try {
        } catch (Exception e) {
            logger.warn("Can't close socket: " + peer.toString(), e);

        Message responseMessage = gson.fromJson(response, Message.class);
        return responseMessage;


I can't figure out what is the problem with my code. 

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 netty+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to