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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:35:39+00:00 2026-05-30T09:35:39+00:00

Why does nothing get printed out to the console? I have a server socket

  • 0

Why does nothing get printed out to the console?

I have a server socket which starts a new thread for each client. It reads a line from the client outputs it and sends a response of its own. This is printed on the client side. Here’s the code:

The client code:

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

public class Client {
    public static void main(String[] args) {
        PrintWriter out = null;
        BufferedReader in = null;
        Socket echoSocket=null;
        try {
            echoSocket = new Socket("localhost", 8999);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
            for(int i=0;i<20;i++) {
                out.print("Sending to Server"+i);
                System.out.println("Received from Server"+in.readLine());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                try {
                    in.close();
                } finally {
                    try {
                        out.close();
                    } finally {
                        echoSocket.close();
                    }
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}    

The server code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Server {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            final ServerSocket server = new ServerSocket(8999);
            final ExecutorService threadPool = Executors.newFixedThreadPool(2);
            while (true) {
                try {
                    final Socket sock = server.accept();
                    threadPool.submit(new Callable<Void>() {
                        @Override
                        public Void call() throws Exception {
                            BufferedReader br = null;
                            PrintWriter out = null;
                            try {
                                br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
                                out = new PrintWriter(sock.getOutputStream(), true);
                                for (int i = 0; i < 20; i++) {
                                    String readLine = br.readLine();
                                    System.out.println(readLine);
                                    out.print(readLine + "response");
                                }
                            } finally {
                                try {
                                    br.close();
                                } finally {
                                    try {
                                        out.close();
                                    } finally {
                                        sock.close();
                                    }
                                }
                            }
                            return null;
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
  • 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-30T09:35:40+00:00Added an answer on May 30, 2026 at 9:35 am

    Well for one, you should probably println instead of print on your writers (in both client and server).

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

Sidebar

Related Questions

I have a tiny shell in C which does nothing but print Hello, im
I have the following code which does nothing but reading some values from a
What does array_search() return if nothing was found? I have the need for the
In my code I have a variable myCash , which is printed into an
I have a bunch of reports that are printed out and mailed to clients.
I have this Trigger in Postgresql that I can't just get to work (does
I just uploaded working site files to a new server which I know is
I've written a templated user control, MinimalTemplate, which currently does nothing other than render
I have an activity that extends ViewFactory. The activity does nothing more than act
SISS 2008 - My package goes green very quickly, but does nothing. The connections

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.