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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:54:35+00:00 2026-06-13T12:54:35+00:00

In First class have method listen which listening client socket public void listen() throws

  • 0

In First class have method “listen” which listening client socket

public void listen() throws IOException {       

        while (true) {
            socket = this.serverSocket.accept();

            DataOutputStream out = new DataOutputStream( socket.getOutputStream() );
            this.outputStreams.put(socket, out);


            Thread miltiServer;

            miltiServer = new Thread() {
                @Override
                public void run() {                    
                    InputStream sin = null;

                    try {                   
                        sin = socket.getInputStream();
                        ObjectInputStream in = new ObjectInputStream(sin);
                        message = (AgentData) in.readObject();

                    } catch (ClassNotFoundException ex) {

                    } catch (IOException ex) {

                    } 
                }
            };

            miltiServer.start();
        }

In Second class i need to read and analyze messages which recieved from client socket. I don’t know how to get messages in other class. I have idea to use Callable interface, but if i use it, return statement will exit from infinitive cycle.

  • 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-13T12:54:36+00:00Added an answer on June 13, 2026 at 12:54 pm

    An easy way for your socket listener to communicate the messages to your Second class is through a BlockingQueue. The listener would read from the socket input stream and call queue.put(...) to add any messages to the queue.

    Then the Second class would be in a loop calling queue.take(); which would return each message when it is added to the queue. If you want unlimited messages to be queued then LinkedBlockingQueue would work. If you want to throttle the messages then a bounded queue such as ArrayBlockingQueue might be more appropriate.

    Both threads would need to share the same BlockingQueue so you will need to construct it and pass it to both threads or put a method on your Second class named something like addMessage(...) and the BlockingQueue would be inside of your Second class. Then the listener would call second.addMessage(...);.

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

Sidebar

Related Questions

I have this middleware which is the first: class RedirectIt require net/https require uri
I have one class. Class First { private Second second; public First(int num, String
I have a web application and two class files, First class is MyClass.class which
my code is like this: i have two classes first class: public class Box<E>
I have a class like Quete (first in , first out) public class Tor<T>
I have a centralized socket class which is responsible for sending and retrieving data.
I am learning Javascript and I have read functions are first class objects and
I have this view (DetailsContainer, first class in code section of this question) with
I have this application with 2 classes, in the first class I define a
Using Dozer to map two objects, I have: /** /* This first class uses

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.