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

  • Home
  • SEARCH
  • 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 6943615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:10:45+00:00 2026-05-27T13:10:45+00:00

I am wondering about, how I can wait a ServerSocket connection on Socket client

  • 0

I am wondering about, how I can wait a ServerSocket connection on Socket client side.

When I execute the server (send) first, it waits the client connection with the method ServerSocket.accept. The problem is that the client (receive) cannot be executed without the server has been executed first. I would like add a condition to allow the client to wait the connection from the server. Is it possible?

SEND (server)

ServerSocket servsock = new ServerSocket(1234);
Socket sock = servsock.accept();

RECEIVE (client)

Socket sock = new Socket(from, 1234);

ERROR (client)

java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at java.net.Socket.<init>(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:189)

Thank you.

  • 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-27T13:10:46+00:00Added an answer on May 27, 2026 at 1:10 pm

    Thank to Mat, it works.

        Socket sock = null;
        while (true) {
          try {
           sock = new Socket(from, 1234);
           if (sock != null) { break; }
           }
          catch (IOException e) { Thread.sleep(1000); }
        }
        // rest of the code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been wondering about temp tables in sp's and how all that can
I am wondering how I can go about stopping a dialog from opening if
I'm wondering that how much worried I should be about data types. I can
I wondering about how in T-SQL can I retrieve - let's say - 1/2
I've been wondering about alternative ways to write control structures like you can write
I'm quite familiar with the System.Diagnostics.Process class. But, I'm wondering about how I can
I'm wondering about a couple of things about Nant: Can I test an execution
Well I am wondering to know about How can I remove profile information step
I've been wondering about this for a while and I can't see why Google
I'm wondering about writing an application in Java which can synchronize files across my

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.