Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:32:38+00:00 2026-06-12T09:32:38+00:00

With Netty’s new 4.x API, there have been some changes (some big some small).

  • 0

With Netty’s new 4.x API, there have been some changes (some big some small). I have migrated an old server core of mine to work with the new API, but I cannot figure out a way to solve this problem. In 3.x, I could use

     MessageEvent e

This allowed me to cast e to the type I needed (in this case, ServerMessage and String, as those were the two types used for server->client messages).

When using 3.x, I could do:

  public void writeRequested(ChannelHandlerContext chctx, MessageEvent e)
    {
        if(e.getMessage() instanceof ServerMessage) //change 
        {
         ServerMessage message = (ServerMessage) e.getMessage();
        Channels.write(chctx,e.getFuture(),message.getData());
        logger.debug("Message sent (id: "+message.getMessageID()+ " data: "+message.getMessageBody()+")");


    }

        else if(e.getMessage() instanceof String)
        {
            String data =(String)e.getMessage();
            ChannelBuffer buffer = ChannelBuffers.buffer(data.length());
            buffer.writeBytes(data.getBytes());

            Channels.write(chctx,e.getFuture(),buffer);

            logger.debug("Written string (possible <policy-file-request />) to client #id ->" +
                    +Environment.getGameInstance().getManager().getSession(chctx.getChannel());
        }
    }

However, with 4.x, I am a bit confused to what I can use. I have partially implemented simple sending like so;

public void encode(ChannelHandlerContext ctx, ServerMessage msg, ByteBuf buffer) {

   if(msg instanceof ServerMessage) {

        ServerMessage message = (ServerMessage)msg;
        ctx.channel().write(message.getData());
        logger.debug("Message sent (id: "+message.getMessageID()+ " data: "+message.getMessageBody()+")");

   }
    else {
                 // string stuff here
            }
   }

My basic problem is that how would I go about writing a String as well as a ServerMesssage to the client?
(My String is a simple )

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:32:39+00:00Added an answer on June 12, 2026 at 9:32 am

    Just use the common super-class of the two messages and then cast as you did in 3.x if you really want to use the same ChannelHandler for both Objects. Anyway I think it would be much more clean if you just use two different ChannelHandler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questions about Netty (Server Side), TCP/IP applications; I am wondering if
I have a netty pipeline such as: return Channels.pipeline( new ObjectEncoder(), new ObjectDecoder(), new
I have been studying Netty and Mina but am confused as to the best
Which JVM does Netty Use? I am new to Server Development. I am a
I'm writing small utility app (JBoss Netty based) which should perform some trivial login
I have server application based on Netty. It decode message (from json) and send
I wrote a small netty server program. It is working with all phones, but
I have a netty web socket server running to which various native javascript clients
I just started working with Netty. I already have a server, and im writing
I have a Netty TCP server, and I want to reject/refuse incoming connection attempts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.