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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:03:13+00:00 2026-05-16T04:03:13+00:00

Here One server and one client is there. And communication has been maintained by

  • 0

Here One server and one client is there. And communication has been maintained by selectable Channel.
like–
Server —

  SelectionKey selectKey = channel.register(this.selector,

        SelectionKey.OP_ACCEPT);

while (selectKey.selector().select() > 0) {

    Set<SelectionKey> selectedKeys = this.selector.selectedKeys();

    Iterator<SelectionKey> iterator = selectedKeys.iterator();

    while (iterator.hasNext()) {

        SelectionKey key = iterator.next();

        iterator.remove();

        if (key.isAcceptable()) {

            ServerSocketChannel nextChannel = (ServerSocketChannel) key

                        .channel();
            SocketChannel newChannel = nextChannel.accept();

            newChannel.configureBlocking(false);

            if (!newChannel.isRegistered()) {

                SelectionKey selectionKey = newChannel.register(

                     this.selector, SelectionKey.OP_READ

                | SelectionKey.OP_WRITE);

                selectionKey.attach(newChannel);

            }

        } else if (key.isWritable()) {

             SocketChannel attachment1 = (SocketChannel)key.attachment();
             ByteBuffer writeBuffer = ByteBuffer.wrap("Hello".getBytes());

                attachment1.write(writeBuffer);

                System.out.print("Written");
            }
         }
      } 

Client :

   InetSocketAddress isa = new InetSocketAddress(InetAddress
            .getLocalHost(), 4444);
    SocketChannel sc = null;

    try {

        while (true) {

            Thread.sleep(10000);
            sc = SocketChannel.open();
            sc.connect(isa);
            ByteBuffer byteBuffer = ByteBuffer.allocate(BUFSIZE);
            int nbytes = sc.read(byteBuffer);
            byteBuffer.flip();
            dbuf.flip();
            CharBuffer cb = decoder.decode(byteBuffer);
            System.out.println(isa + " : " + cb);

        }

The Problem is that every time client read the data up to full size of buffer limit of client instead of sent data limit.

  • 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-16T04:03:14+00:00Added an answer on May 16, 2026 at 4:03 am

    This is the way TCP sockets work — they are a stream of bytes, not a sequence of messages.

    You’ll need to design in a higher level protocol so that the receiver can re-discover the message boundaries after it receives the bytes.

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

Sidebar

Related Questions

There is a group here using Java, server-side and client-side, with Swing for the
We have 3 identical HP DL380 G5 server here, one of them is running
I'm using RSA to encrypt communication between a server and a client. Lets say
I'm using VisualSVN client and server and one of the requirements for web projects
So, I have two threads. Thread one manages the client connections. (There is only
I have one stand alone client server application. I want to move it to
When implementing a client/server solutions, one of the questions you always need to answer
I'm currently writing a project in Python which has a client and a server
Simple one here... is there a clean way of preventing a user from double-clicking
Here one more basic question asked in MS interview recently class A { public

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.