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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:41:02+00:00 2026-06-06T19:41:02+00:00

I have a java application that people can log into (and do various things

  • 0

I have a java application that people can log into (and do various things with a database with, but that’s not important). I can use the .getInetAddress() to get the IP addresses of the people logged into the server, however I am not sure how exactly to communicate between the threads. I am trying to add a chat service to this pre-existing program.

My program uses a standard multi-threaded server, and the clinet is a single threaded AWT Action Listener program. What is the best way to do this? My code includes a class containing main that creates a new “Client Handler” class and creates a new thread to handle it. Currently there is no inter-thread communication, the thread spawns on it’s own socket port and runs independently on the server. My previous thoughts include:

Put the client into a blocking state with ObjectInputStream and wait for the client to receive a message (instead of busy waiting for a button to be pressed), with the condition that when the client goes to perform an action (edit a field), it would release the blocking I/O and perform the method, then go back to the blocked I/O “Waiting” stage of the program.

Things I’m not sure about this:

  1. If i invoke the blocking I/O, will the AWT ActionListener unblock the blocking I/O and jump to the event handler?

  2. If the client is in code (not on the blocking InputStream) and a message is sent, will the server know to wait until the program is back on the inputStream before it sends the message, or will it send the message and create a queue, or worse cashe, problem.

  3. The server is multithreaded, If John is at 192.168.1.100 and Larry is at 192.168.1.152 and John wants to send a message to Larry, how do I get the message from thread handling *.100, to thread handling *.152 so it can be outputted to the right client on the right socket.

My other thought (and maybe the easier one) would be to make the client multi-threaded, connect to the server on a different port, and use a whole different set of socket connections to handle the events. In this case i can just use a blocking I/O wait, when i get the message, output it, and then go back to the blocking I/O. There wouldn’t be any issues in miss communication between the production code and the chat code, and from that stance it is better, however this means I would need to have 2 open connections on different ports for every client that connects. The program will eventually have thousands of users connected to it at one time, and I do not want to hog all the server ports with one application.

Are their other ways of doing this without flooding the ports or risking communication errors?

  • 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-06T19:41:06+00:00Added an answer on June 6, 2026 at 7:41 pm

    Your client should be using 3 threads. All gui interactions should be done from the EDT. Then, you should have a thread for the socket InputStream and a thread for the socket OutputStream (both of which block can potentially block). when you want to send a message, your gui thread should use some sort of thread-safe queue to pass the message to the OutputStream thread. any messages received by the InputStream thread should use something like SwingUtilities.invokeLater to push the message to the gui.

    i’m not exactly sure what you are saying about the sockets and ports. every client which is connected to the server will require a separate socket connection (which will involve a separate port)

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

Sidebar

Related Questions

I have a java application that runs out of memory, but I have no
I have a Java application that makes heavy use of a large file, to
I have written a java application that sporadically logs events to an SQLite database
i have to write small java database application with several tables. With that i
I have a web application that I build with Maven into a war. But
I have a Java application that is managed using Maven. The project involves the
I have a Java application that needs to collect and report a large number
i have an Java J2ME application that does (at user request) create HttpConnections to
I have a few JAVA application that I monitor using JMX. I would like
I have made a java application that stores data from a .csv file to

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.