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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:13:17+00:00 2026-06-16T07:13:17+00:00

Situation I’ve been creating a program to exchange messages between two computers in the

  • 0

Situation

I’ve been creating a program to exchange messages between two computers in the LAN. One computer identifies itself as the server while the other is a client. Upon startup, the user has to enter the Host and the Port of another computer, should he wish to connect as a client to that machine.
The setup of how it works is very basic: You type your message, hit enter and it shows up on your own screen. After that your conversation partner has to click a button to retrieve the latest messages and it should show up on his screen. This goes on untill someone leaves.

Problem

The program launches correctly and asks for the connection settings. After that I initiate the connection on both computers and things seem to go fine (after the connection is established, a label shows you what your status, e.g. Client or Server, is (1)). Things continue looking fine when I enter a message and send it, the output gets written to the sender’s screen and no unexpected behaviour occurs.

When I want to retrieve the messages on the other computer, the program completely freezes. No objects in the GUI are clickable and no output is shown.

Code

Assuming the connection is correctly established (see (1)), I will outline the process of sending a message below while leaving out the non-essential parts.

GuiApplication.java

private void sendMessage() {
    connection.sendMessage(message);
    showMessage(message);
}

Connection.java
public void sendMessage(String message) {
    if (isClient()) {
        client.sendMessage(message);
    } else if (isServer()) {
        server.sendMessage(message);
    }
}

Client.java
public void sendMessage(String message) {
    outbound = new PrintWriter(socket.getOutputStream(), true); // Defined outside this method
    outbound.println(message);
}

The process of sending a message is pretty straightforward, but I wanted to include it just in case I’ve overlooked something.

What follows is the code I’ve created to retrieve the new messages. The concept is simple: I check if there are any new messages and if there are, I retrieve them.

GuiApplication.java
if (connection.hasNewMessage()) {
    message = connection.retrieveMessage();
}
showMessage(message);

The first part (connection.hasNewMessage()) will check whether or not the program is either running the client or the server and call the appropriate retrieveMessage().

Client.java
public String retrieveMessage() throws IOException {
    inbound = socket.getInputStream(); // Defined outside this method
    return IOUtils.toString(inbound, "UTF-8");
}

At first I’ve tried this with a BufferedReader using an InputStreamReader and calling the readLine() method, but decided to try out the commons.io method once I noticed it didn’t work (the same problem as I am currently facing).

Question

It’s been made pretty clear by now: why does my program hang the moment I click a button which retrieves new messages?

External

I’m not sure if it’s frowned upon, but here’s the github repository in case you wanted a better overview, although I believe the necessary code snippers are there.

  • 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-16T07:13:19+00:00Added an answer on June 16, 2026 at 7:13 am

    I did look at your code, and as I suspected, your problem has absolutely nothing to do with the code you’ve posted. Your GUI completely ignores Swing threading rules, and calls long-running tasks on the main Swing event thread known as the Event Dispatch Thread or EDT. Since this thread is responsible for all Swing drawing and user interaction, your GUI is prevented from doing this and becomes completely frozen.

    Please read Concurrency in Swing for the details on this.

    And next time, please post an sscce so we don’t have to dive into a huge amount of your source code! The key to the SSCCE is to eliminate all code not essential to your problem at hand. This is not easy to do and will require a lot of work from you to create, so that it has enough code to run, but not too much as to drown us in code, but then you are asking volunteers to help you on their free time, so it’s not asking too much.

    Best of luck!

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

Sidebar

Related Questions

Situation: I have a multithreaded program written in C. If one of the threads
Situation: I have been creating webpages in HTML5/CSS3 & Javascript using Sublime 2 text
Situation: 1. Linux TCP server 2 Windows C# client application The server receives messages
Situation is simple. I need to wrap text around two inline objects (buttons with
Situation I am trying to redirect all my traffic to the index.php file one
Situation: I am writing a program to solve for primes. I need to solve
Situation I'm creating a C#/WPF 4 application using a SQL Compact Edition database as
Situation: I have a C# program which does the following: Generate many files (replacing
Situation: I am creating an app in C# that uses Oracle.DataAccess.Client (11g) to do
Situation: I got one input field and it needs to check if the input

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.