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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:23:35+00:00 2026-06-12T10:23:35+00:00

I made a server myself using java nio and a selector. I can receive

  • 0

I made a server myself using java nio and a selector. I can receive the data and answer directly from the client if needed.

But now I want a thread that will process data, and anytime it will send data to each client.

So how can I do that? Also how to keep in memory all channels to write the data to each client ?

If you need I can post the part of my code with java nio.

  • 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-12T10:23:36+00:00Added an answer on June 12, 2026 at 10:23 am

    Create a new thread with a runnable and make sure it knows your server because your server should know all clients. If a client sends a message parse it through the data processor thread and let it do it’s job. When it’s done processing your task then let the server know so he can update all clients.

    Tip: you should make a waiting queue for the processing thread with something like a LinkedBlockingQueue so you can always put tasks on the queue without waiting for the task to finish. Then the thead will wait for things on the queue that need to be processed. This way the processing thread will only use CPU resources when there are actually tasks on the queue

    Here is a code example

    public abstract class Queue implements Runnable {
    private final LinkedBlockingQueue<Message> queue;
    
    public Queue() {
        this.queue = new LinkedBlockingQueue<Message>();
    }
    
    /**
     * Adds a message to the queue.
     * @param message
     */
    public void add(final Message message) {
        try {
            queue.put(message);
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Waits for new messages
     */
    @Override
    public void run() {
        while(true) {
            try {
                final Message message = queue.take();
                processMessage(message);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    /**
    * Processes the new message
    */
    protected abstract void processMessage(Message message);
    

    }

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

Sidebar

Related Questions

Using Java sockets, I made a simple server. This works because it sends data
I made server/ client application in WCF. How get count of connected clients? And
i have made a server using php. The server is getting new information after
I've made a websocket server with websocketpp (C++), and a websocket client in PHP.
Long time ago I made a socket based server application using the principle of
I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
Using MS SQL Server .I have made a Stored Procedure named SP_Get_CallsLogged . I
I have made a full application in JQM using cakePHP as the server side
I need to do a client-server application, the client will be made with python-gtk,
JCollider is a Java client for the SuperCollider sound synthesis server. It has a

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.