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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:53:52+00:00 2026-06-15T23:53:52+00:00

I am trying to send file info from server to client, but can’t receive

  • 0

I am trying to send file info from server to client, but can’t receive the info on the client side. I think it’s an error with streams but can’t find it.

I debug the code and I see that the info is reading well but then something bad happend when comes to the line :

while ((readLine = read.readLine()) != null) {

It’s null and everything ends.

public class Server {
    private String urlFile = "http://riemann.fmi.uni-ofia.bg/vladov/students/boil.txt";
    private ServerSocket serverSocket = null;
    private BufferedReader read = null;
    private BufferedWriter write = null;
    private FileReader fileReader = null;
    URLConnection urlConnection = null;

    void acceptConnection() {
        try {
            serverSocket = new ServerSocket(3000);
            Socket client = null;
            while (true) {
                client = serverSocket.accept();
                handleConnection(client);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void handleConnection(Socket clientSocket) {
        try {
            URL url = new URL(urlFile);
            urlConnection = url.openConnection();
            read = new BufferedReader(new InputStreamReader(
                    urlConnection.getInputStream()));

            write = new BufferedWriter(new OutputStreamWriter(
                    clientSocket.getOutputStream()));
            String readLine = null;
            while ((readLine = read.readLine()) != null) {
                write.write(readLine);
                write.flush();
            }

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void tearDownConnection() {
        try {
            write.close();
            read.close();
            serverSocket.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

Client:

 public class Client {
    Socket client = null;
    BufferedReader reader = null;
    BufferedWriter writer = null;

    void connectToServer(String hostAddress, int port) {
        try {
            System.out.println("Client is waitting.");
            client = new Socket(hostAddress, port);
            reader = new BufferedReader(new InputStreamReader(
                    client.getInputStream()));
            writer = new BufferedWriter(new OutputStreamWriter(
                    client.getOutputStream()));
            String readedLine = null;
            readedLine = reader.toString();
            while ((readedLine = reader.readLine()) != null) {
                System.out.println(readedLine);
            }

        } catch (UnknownHostException e) {
            System.out.println("Host name is unkown.");
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void tearDownConnection() {
        try {
            if (client != null) {
                client.close();
            }
            if (writer != null) {
                writer.close();
            }
            if (reader != null) {
                reader.close();
            }

        } 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-06-15T23:53:53+00:00Added an answer on June 15, 2026 at 11:53 pm

    The client is waiting for a line (ie. terminated by a return/newline character) whereas server is not sending this. You could add the newline yourself in Server:

    while ((readLine = read.readLine()) != null) {
      write.write(readLine+"\n");
      write.flush();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send a file in chunks to an HttpHandler but when I
I've been trying to send a file to an ftp server via an FTPClient
I am trying to send an email with an attached file to it but
I'm trying to receive a variable length stream from a camera with python, but
I'm trying to assemble a CSV file from some DB data and send it
i am implementing one app related to send file to server. i am trying
I am trying to send an XML file from a textfield in my html,
I'm trying to send an audio file to a PHP server. Here is the
I'm trying to send a file to the browser to download, and not having
I am trying to send a file to the browser in a Zend Framework

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.