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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:21:11+00:00 2026-05-31T13:21:11+00:00

suppose we use the following classes to illustrate a client and a server :

  • 0

suppose we use the following classes to illustrate a client and a server :

Client

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    private PrintWriter toServer;
    private BufferedReader fromServer;
    private Socket socket;

    public Client() throws IOException {
        socket = new Socket("127.0.0.1", 3000);
    }

    public void openStreams() throws IOException {
        toServer = new PrintWriter(socket.getOutputStream(), true);
        fromServer = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));
    }

    public void closeStreams() throws IOException {
        fromServer.close();
        toServer.close();
        socket.close();
    }

    public void run() throws IOException {
        openStreams();
        String msg = "";
        Scanner scanner = new Scanner(System.in);
        toServer.println("Hello from Client.");
        while (!"exit".equals(msg)) {
            System.out.println(">");

            toServer.println("msg");
            String tmp = fromServer.readLine();
            System.out.println("Server said: " + tmp);
        }

        closeStreams();
    }
}

Server

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class myServer {
    private static ServerSocket serverSocket;
    private static Socket socket;
    private static PrintWriter toClient;
    private static BufferedReader fromClient;

    public static void run() throws IOException {
        System.out.println("Server is waiting for connections...");

        while (true) {
            openStreams();
            processClient();
            closeStreams();
        }
    }

    public static void openStreams() throws IOException {
        serverSocket = new ServerSocket(3000);
        socket = serverSocket.accept();
        toClient = new PrintWriter(socket.getOutputStream(), true);
        fromClient = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));
    }

    public static void closeStreams() throws IOException {
        fromClient.close();
        toClient.close();
        socket.close();
        serverSocket.close();
    }

    public static void processClient() throws IOException {
        System.out.println("Connection established.");
        String msg = fromClient.readLine();
        toClient.println("Client said " + msg);
    }
}

if , we run the server first and then after server is ready, we run the client, we would get the following error:

Error in Client Software caused connection abort: recv failed

what is the problem?

  • 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-31T13:21:11+00:00Added an answer on May 31, 2026 at 1:21 pm

    maybe you can try to use older version of java, similar thing happened to me and when i used sdk 1.6 instead of 1.7 everything fixed

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

Sidebar

Related Questions

Suppose you use the following structure: var Args = new Object(); Args.Age = '10';
Suppose you have two seperate ASP.NET Web Application projects that both need to use
Suppose we have following two classes: class Temp{ public: char a; char b; };
Suppose that you have the following hierarchy of statistics-related classes, structured in a manner
Let's suppose the following use case: for a working example plese look at this
Suppose I use a custom :format to implement a gadget-oriented version of my site.
Suppose both parent and child use one pipe for writing and reading means when
Suppose I have a Window with TextBoxes I want to use the values. Right
What I'm suppose to do is use a trigger to update the quantity sold
How do you use variables to access Object attributes? Suppose I have an Object

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.