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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:12:42+00:00 2026-05-29T07:12:42+00:00

I am learning currently about client server communication using Java through sockets. First of

  • 0

I am learning currently about client server communication using Java through sockets.
First of all I retrieve my own machine’s IP Address using following code.

InetAddress ownIP=InetAddress.getLocalHost();
//the result being 192.168.56.1

Now I write the simple client server application using the above mentioned address as follow

public class SimpleClientServer {
public static void main(String[] args)
{
    //sending "Hello World" to the server
    Socket clientSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    try
    {

        clientSocket = new Socket("192.168.56.1", 16000);

        out = new PrintWriter(clientSocket.getOutputStream(), true);

        in = new BufferedReader(new InputStreamReader(
                                                 clientSocket.getInputStream()));

        out.println("Hello World");

        out.close();
        in.close();
        clientSocket.close();
    }
    catch(IOException e)
    {
        System.err.println("Error occured " + e);

    }
}
}

The result hower reads a follow.

Error occured java.net.ConnectException: Connection refused: connect

What is the reason for this. Is it just the wrong host address?

  • 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-29T07:12:43+00:00Added an answer on May 29, 2026 at 7:12 am

    From the code you have given you seem to suggest that there is currently nothing listening on port 16000 for the socket to connect to.

    If this is the case you need to implement something like

    ServerSocket serverSocket = null;
    try {
        serverSocket = new ServerSocket(16000);
    }
    catch (IOException e) {
        System.err.println("Could not listen on port: 16000.");
        System.exit(1);
    }
    

    More information can be found in the Java online documentation and a full example is included.

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

Sidebar

Related Questions

I am currently learning about basic networking in java. I have been playing around
I'm currently learning about concurrency in C++ and came across using a vector of
I am currently learning about named pipes in Windows using ASP.NET 3.5 and C#.
I am currently learning about object serialization in Java and in my understanding it
I'm currently learning about class inheritance in my Java course and I don't understand
I currently learning about scrum and want to learn from experienced professionals in the
I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about
I am currently learning C# and LINQ. I have lots of questions about them.
im currently learning stacks in java and have a quick question. what will the
I'm currently learning to develop for the .net compact framework using c# in VS2008

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.