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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:39:40+00:00 2026-06-06T15:39:40+00:00

I am writing a Java client/server GUI application using sockets and here is the

  • 0

I am writing a Java client/server GUI application using sockets and here is the problem:

I have a button to start listening for a specified port:

button actionPerformed method

private void listenButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    int port = Integer.parseInt(portTextfield.getText(), 10);

    try {
        socket.listen(port);
    } catch (IOException ex) {
    }
}

Here is the socket.listen method

public static void listen() throws IOException {
    ServerSocket ss = new ServerSocket(port);

    while (true)
        new socket(ss.accept());
}

“socket” class extends “Thread”
So after ss.accept() returns a value it creates new socket instance in separate thread.

After clicking the button the GUI freezes because inside the socket.listen method there is an infinite loop. How can I avoid that?

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

    You have two pitfalls in your design:

    1. ss.accept() is a blocking call so your UI will freeze until there is an incoming connection
    2. Never run while(true) loops in the EDT.

    Instead do the following:

    • When the button is clicked create a thread that will start listening for incoming connections.
    • Whenever you have an incoming connection, create another thread that will take the incoming client connection and deal with it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a client-server application using Java-RMI. Some server-side ressources have to be
I'm writing a client/server application in Java and I'm using TCP to transfer data
I'm currently writing a simple client/server in Java using sockets. I want the server
I am writing an application that communicates using sockets. I have a server running
I'm currently writing a jdbc client-server socket application in java. I've been having a
I am writing a server application in Java where i have in an activation
I'm writing a client-server solution which is using Java RMI (Via the Cajo project).
I'm writing a multithreaded C++ server and a Java client using TCP. It works
I'm writing RTSP server and have some problems. I'm using VLC as client. Server
I am writing some java TCP/IP networking code ( client - server ) in

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.