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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:01:32+00:00 2026-05-26T08:01:32+00:00

I am building a Client server app in java ,here is my code Client

  • 0

I am building a Client server app in java ,here is my code

Client

import java.net.*;
import java.io.*;

class ClientCode{
    public static void main(String args[]) throws Exception {
        int character;
        Socket socket = new Socket("112.134.214.53", 8765);
 //i have put my public ip instead of 127.0.0.1 in order to test it is working through the internet or not
        InputStream in = socket.getInputStream();
        OutputStream out = socket.getOutputStream();
        String string = "Hello!\n";
        byte buffer[] = string.getBytes();
        out.write(buffer);
        while ((character = in.read()) != -1){
            System.out.print((char) character);
        }
        socket.close();
    }
}

Server

import java.io.*;
import java.net.*;
public class ServerCode{
    public static void main(String[] args ){
        try{
            ServerSocket socket = new ServerSocket(8765);
            Socket insocket = socket.accept( );
            BufferedReader in = new BufferedReader (new InputStreamReader(insocket.getInputStream()));
            PrintWriter out = new PrintWriter(insocket.getOutputStream(), true);
            String instring = in.readLine();
            out.println("The server got this: " + instring);
            insocket.close();
        }
        catch (Exception e) {}
    }
}

both are running on a same machine connected to internet using my home adsl single port router.

Server application run fine but when my client connects to the server through public ip the problem starts ,below is the error message

Exception in thread "main" java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at ClientCode.main(ClientCode.java:6)

My Kaspersky Network monitor is showing me that my port 8765 is ok and working

  • 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-26T08:01:33+00:00Added an answer on May 26, 2026 at 8:01 am

    There may be two possible reasons for this exception to occur:

    1- There is no service listening to the port you are attempting to connect to. For debugging you can try loading http://112.134.214.53:8765 using a browser and see if it connects with the server.

    2- (If everything else is fine) This could very well be a firewall issue.

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

Sidebar

Related Questions

I'm building a .NET remoting client/server that will be transmitting thousands of files, of
Below is partial code to an experimental http server app I'm building from scratch
I am building a scalable Server Side App in Java but I need to
I have been building a client / server app with Silverlight, web services, and
I'm building an Objective-C app that has both a server and a client. The
I am building a Java Google App Engine server project and a Java desktop
I'm building an client/server-app where I want to sync data. I'm thinking about including
I am looking at building a client server application in C# using winforms or
I'm building a simple client-server chat system. The clients send data to the server
I'm building a client that talks to the http server. Now my client needs

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.