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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:51:45+00:00 2026-05-14T06:51:45+00:00

I am new to Apache MINA kindly guide me how to read from IoSession.

  • 0

I am new to Apache MINA kindly guide me how to read from IoSession. I have stored a POJO in it.

public static EchoUDPServerDiscoveryObjectResponseProperties echoProperties

session.write(echoProperties);
  • 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-05-14T06:51:45+00:00Added an answer on May 14, 2026 at 6:51 am

    Custom Client:

    package client;
    
    import java.net.InetSocketAddress;
    import java.nio.charset.CharacterCodingException;
    import java.nio.charset.Charset;
    import java.util.logging.Level;
    import org.apache.mina.core.buffer.IoBuffer;
    import org.apache.mina.core.future.ConnectFuture;
    import org.apache.mina.core.future.IoFutureListener;
    import org.apache.mina.core.future.ReadFuture;
    import org.apache.mina.core.service.IoConnector;
    import org.apache.mina.core.service.IoHandlerAdapter;
    import org.apache.mina.core.session.IdleStatus;
    import org.apache.mina.core.session.IoSession;
    import org.apache.mina.example.udp.client.MemMonClient;
    import org.apache.mina.transport.socket.nio.NioDatagramConnector;
    
    /**
     *
     * @author az
     */
    public class CustomClient extends IoHandlerAdapter{
    
        private IoSession session;
        private IoConnector connector;
        private ConnectFuture connFuture;
    
        public CustomClient() throws InterruptedException{
            connector = new NioDatagramConnector();
            connector.setHandler(this);
            connFuture = connector.connect(new InetSocketAddress("192.168.3.22",6502));
    
    
            connFuture.addListener(new IoFutureListener<ConnectFuture>() {
                public void operationComplete(ConnectFuture future) {
                    if (future.isConnected()) {                    
                        session = future.getSession();
                        try {
                            try {
                                sendData();
                              //  connFuture.await();
    
                            } catch (CharacterCodingException ex) {
                                java.util.logging.Logger.getLogger(MemMonClient.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } 
                }
            });
    
        }
        private void sendData() throws InterruptedException, CharacterCodingException {
    
    
                IoBuffer buffer = IoBuffer.allocate(8);
                buffer.setAutoExpand(true);
                buffer.putString("any", Charset.forName("UTF-8").newEncoder());
                buffer.flip();
                session.write(buffer);
        }
    
         @Override
        public void exceptionCaught(IoSession session, Throwable cause)
                throws Exception {
            cause.printStackTrace();
        }
        @Override
        public void messageReceived(IoSession session, Object message)
                throws Exception {
            connFuture.getSession().getConfig().setUseReadOperation(true);
    
            ReadFuture r = connFuture.getSession().read();
            connFuture.await();
            connFuture.getSession().getConfig().setUseReadOperation(true);
    
    
            Object obj = r.getMessage();
            System.out.println("r.getMessage(); "+obj);
            IoBuffer buffer = IoBuffer.allocate(2048);
                            buffer.setAutoExpand(true);                     
                            Object objReceived = buffer.getObject();
                            System.out.println(objReceived.toString());
    
            System.out.println("reveived Session recv...");
        }
    
        @Override
        public void messageSent(IoSession session, Object message) throws Exception {
            System.out.println("Message sent...");
        }
    
        @Override
        public void sessionClosed(IoSession session) throws Exception {
            System.out.println("Session closed...");
        }
    
        @Override
        public void sessionCreated(IoSession session) throws Exception {
            System.out.println("Session created...");
        }
    
        @Override
        public void sessionIdle(IoSession session, IdleStatus status)
                throws Exception {
            System.out.println("Session idle...");
        }
    
        @Override
        public void sessionOpened(IoSession session) throws Exception {
            System.out.println("Session opened...");
        }
        public static void main (String are[]){
            try{
            new CustomClient();
            }catch(Exception ex){ex.printStackTrace();}
        }
    }
    
    POJO Java
    package pojo;
    
    import java.io.Serializable;
    
    /**
     *
     * @author az
     */
    public class kojo implements Serializable{
        private String name = "null";
        private String address = "null";
    
        /**
         * @return the name
         */
        public String getName() {
            return name;
        }
    
        /**
         * @param name the name to set
         */
        public void setName(String name) {
            this.name = name;
        }
    
        /**
         * @return the address
         */
        public String getAddress() {
            return address;
        }
    
        /**
         * @param address the address to set
         */
        public void setAddress(String address) {
            this.address = address;
        }
    
    }
    
    Custom Server Java
    package server;
    
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import org.apache.mina.transport.socket.DatagramSessionConfig;
    import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
    
    /**
     *
     * @author az
     */
    public class CustomServer {
    
        public CustomServer(){
            try {
                NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
                acceptor.setHandler(new ServerHandler(this));
                //DefaultIoFilterChainBuilder filter = acceptor.getFilterChain();
                DatagramSessionConfig dcfg = acceptor.getSessionConfig();
                dcfg.setReuseAddress(true);
                acceptor.bind(new InetSocketAddress(6501));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    
        public void receiveUpdate(){
    
        }
        public static void main(String are[]){
            new CustomServer();
        }
    }
    
    Server Handler
    package server;
    
    import java.nio.charset.Charset;
    import org.apache.mina.core.buffer.IoBuffer;
    import org.apache.mina.core.future.WriteFuture;
    import org.apache.mina.core.service.IoHandlerAdapter;
    import org.apache.mina.core.session.IdleStatus;
    import org.apache.mina.core.session.IoSession;
    
    /**
     *
     * @author az
     */
    public class ServerHandler extends IoHandlerAdapter {
    
        private CustomServer server;
    
        public ServerHandler(CustomServer server) {
            this.server = server;
        }
    
        @Override
        public void messageReceived(IoSession session, Object message)
                throws Exception {
    
            if (message instanceof IoBuffer) {
                //decode POJO and send to client
                IoBuffer buffer = (IoBuffer) message;
                System.out.println(buffer.getString(Charset.forName("UTF-8").newDecoder()));
                buffer.setAutoExpand(true);
                buffer.putObject(new pojo.POJO());
                buffer.flip();
                session.write(buffer);
    
                System.out.print("Object Attached and Sent");
    
            }
        }
    
        @Override
        public void messageSent(IoSession session, Object message) {
            System.out.println("Message sent");
        }
    
        @Override
        public void sessionClosed(IoSession session) throws Exception {
            System.out.println("Session closed...");
        }
    
        @Override
        public void sessionCreated(IoSession session) throws Exception {
            System.out.println("Session created...");
        }
    
        @Override
        public void sessionIdle(IoSession session, IdleStatus status)
                throws Exception {
            System.out.println("Session idle...");
        }
    
        @Override
        public void sessionOpened(IoSession session) throws Exception {
            System.out.println("Session Opened...");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to java vaadin framework. I have installed APACHE TOMCAT 6 and
I have two servers: Fedora running Apache/2.2.14 (old server) CentOs running Apache/2.2.3 (new server)
I'm really new to apache mod_rewrite module. I have a page called http://abc in
I'm trying to have apache create a new error log file every day, based
I have created a TCP client using Apache Mina. I have added a while
I am new to Apache Xindice. I tried some examples from the internet and
I am facing a strange issue with apache MINA. I have server application which
I'm brand new to Apache Ivy and have posted a few other Ivy-related questions
I'm fairly new to Apache Camel, but have to say that I love it
I'm new to the Apache POI, but what I want to do is read

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.