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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:06:31+00:00 2026-05-27T11:06:31+00:00

The following code is supposed to receive a time from a socket, add 6

  • 0

The following code is supposed to receive a time from a socket, add 6 months to the time and return it to the socket. Here is the code that initializes the sockets and servers:

    //open and connect the sockets
    ServerSocket ss = new ServerSocket(4444);
    System.out.println("1");
    Socket sock = new Socket(ss.getInetAddress(),4444);
    System.out.println("2");
    Socket srv = ss.accept();
    System.out.println("3");

Here is the code that shows the server receiving the time and adding 6 months to it (format of the time is YYYYMMDDHHMMSS).

    //send/receive and increment the current time by 6 months
    PrintWriter bw = new PrintWriter(sock.getOutputStream());
    System.out.println("4");
    bw.print(rtime);
    System.out.println("5");
    //add 6 months to the current time
    long ret = Long.valueOf(new BufferedReader(new InputStreamReader(srv.getInputStream())).readLine()) + 600000000;
    System.out.println("6");

The variable rtime, is a long that is already declared. The code is within a try{} followed by

    catch(Exception e) {
      System.out.println(e);
      System.exit(-1);
    }

I put the printing lines in the code to see where the error takes place, since for some reason, the program terminates without printing an error. All numbers get printed, until “6”. In other words the error is met at the .readline() line. I don’t know what I am doing wrong. Any help is much appreciated, thanks.

  • 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-27T11:06:31+00:00Added an answer on May 27, 2026 at 11:06 am

    Please add

    bw.flush();

    after

    bw.print(rtime);

    This is required to flush the contents from client sockets output stream which would then be available at input of server socket.

    Otherwise, in your example readline(); would not come out as it is a blocking call.

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

Sidebar

Related Questions

I expected the following code to print 8, 111 and 999. I supposed that
I have the following code that determines if it's the first time the user
I have the following python code that expects data coming from the serial port,
The following code is supposed to return current item name typedef enum ItemName {test1,
The following code supposed to add at the beginning of my php files on
I am creating a SMS app the following code is supposed to: check if
Given the following code (it's supposed to write helloworld in a helloworld file, and
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
The following code is supposed to show in a message box the index of
The following code supposed to read a file containing a set of molecular structures,

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.