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 8867625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:05:36+00:00 2026-06-14T17:05:36+00:00

I am using Apache Mina in the server side. I’ve a client which is

  • 0

I am using Apache Mina in the server side. I’ve a client which is written in traditional I/O. Here’s the client side code that sends data to the server.

class SomeClass extends Thread
{
    Socket socket;

    // Constructor
    SomeClass()
    {
        Socket socket = ...
    }

    public void run()
    {
        while (j++ < 10)
        {
            System.out.println("CLIENT[" + clientNo + "] Send Message =>" + requests[clientNo][j]);
            OutputStream oStrm = socket.getOutputStream();
            byte[] byteSendBuffer = (requests[clientNo][j]).getBytes();
            oStrm.write(byteSendBuffer);
            oStrm.flush();
        }
    }
}

The above thread is run for say 20 times. So 20 sockets are created. And in one socket, many messages are send. With a server written using I/O socket classes I’m able to retrieve data perfectly.

The problem comes in the Apache Mina based server which uses BUFFER! I am not able to get individual messages.

How do I get individual messages (given I’m not able to change anything in the client, and the length of individual messages are not known).

Server-side code

Socket Creation

public static void main(String[] args) throws IOException, SQLException {
    System.out.println(Charset.defaultCharset().name());
    IoAcceptor acceptor = new NioSocketAcceptor();
    ProtocolCodecFilter(charset.newEncoder(), charset.newDecoder()));
    acceptor.setHandler(new TimeServerHandler());
    acceptor.getSessionConfig().setReadBufferSize(64);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    acceptor.bind(new InetSocketAddress(PORT));
}

Handler Code

public void messageReceived(IoSession session, Object message) throws Exception {

    AbstractIoBuffer bf = (AbstractIoBuffer)message;
    Charset charset = Charset.forName("UTF-8");
    CharsetDecoder decoder = charset.newDecoder();
    String outString = bf.getString(decoder);
}
  • 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-14T17:05:37+00:00Added an answer on June 14, 2026 at 5:05 pm

    How do i get individual messages

    You don’t. There is no such thing as a message in TCP. It is a byte-stream protocol. There are no message boundaries and there is no guarantee that one read equals one write at the other end.

    (given i’m not able to change anything in client, AND the length of individual messages are not known)

    Your are going to have to parse the messages to find where they stop according to the definition of the application protocol. If that isn’t possible because, say, the protocol is ambiguous, the client will have to be junked. However it seems that as you can’t change the client, it must already work with an existing system, so the guy before you had the same problem and solved it somehow.

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

Sidebar

Related Questions

i want co communicate TCP client server communication using apache mina. can anyone give
In using Apache MINA, I'm sending a login request from the client, which is
I'm using Apache HttpComponents Client to POST to a server that returns JSON. The
I have a client socket which sends messages to the server.I want to get
I have created a TCP client using Apache Mina. I have added a while
Using Apache HttpClient 4.2.1. Using code copied from the form based login example http://hc.apache.org/httpcomponents-client-ga/examples.html
I am currently building a little Apache-Mina Server app. I am using Maven to
I'm trying to build a Java NIO-based socket server using Apache Mina. I really
I am facing a strange issue with apache MINA. I have server application which
I am using Apache Solr to index my data, I have blob field which

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.