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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:23:27+00:00 2026-05-13T14:23:27+00:00

My programme listens for just one connection once… the programme just gets stuck at

  • 0

My programme listens for just one connection once… the programme just gets stuck at clientSocket = serverSocket.accept() if no client connects. I mean I can’t even interrupt it by closing my window. I can’t click any of my buttons in the frame etc.

I’ve used this code the same way in my other programmes but it’s worked fine (I can click text fields and buttons and stuff and type values in them, for this one, it just freezes there until a client connects, can’t even exit).

public void runServer() {
    try {
        serverSocket = new ServerSocket(PORT_NUMBER, 20);
        clientSocket = serverSocket.accept();
        taDisplay.append("Client connected!");
        lblPlayingTo.setText("Playing to: " + objective);

        socketIn = new DataInputStream(clientSocket.getInputStream());
        socketOut = new DataOutputStream(clientSocket.getOutputStream());

        socketOut.writeUTF(serverName);
        clientName = socketIn.readUTF();
        lblEastScore.setText(clientName + ": " + eastScore.getScore());  

    } catch (IOException e) {
        System.out.println(e);
        taDisplay.append("Could not listen on port: " + PORT_NUMBER + ".\n");
    }
}

I’ve removed all my code except this (below) but I still get the same ‘freezing’ problem

    setTitle(title);
    setSize(sizeW, sizeH);
    setVisible(visibility);
    setResizable(resizability);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addKeyListener(new MyKeyAdapter());
    addMouseListener(new MyMouseAdapter());

    //Container
    c = getContentPane();
    c.setLayout(new BorderLayout());
  • 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-05-13T14:23:28+00:00Added an answer on May 13, 2026 at 2:23 pm

    It sounds like you’re doing your serverSocket.accept() call on the GUI’s Event Dispatch Thread (EDT). Swing relies on the EDT for rendering and handling user interaction – if you do a blocking call like “accept”, you won’t see any updates on the GUI.

    What you’ll need to do is create a new thread (or use the application’s “main” thread, which is different to the EDT) that sits on the accept waiting for the client to connect. After the connection it can do any of the work it needs to, but when you want to update the GUI, you need to wrap the code to do the update in a Runnable and pass it to the EDT via SwingUtilities.invokeLater.

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

Sidebar

Related Questions

Part of a programme builds this list, [u'1 x Affinity for war', u'1 x
As a programmer I have no idea how one would go about programming menus
I have a program that listens on a port waiting for a small amount
Hello ladies and gents, I'm having a bit of problem with accept() . I
I have a program that has a broadcast receiver that listens for Phone_State and
My sister is a totally internet radio freak. She listens to internet radio all
Having programmed through emacs and vi for years and years at this point, I
I programmed a bluetooth Television-Remote control for cellphones in J2ME using javax.microedition.lcdui.* (Gauge, List,
A programmer I know has a website that is fully Standards Compliant. It uses
What is a programmer’s life like?

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.