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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:54:34+00:00 2026-05-29T23:54:34+00:00

I am not able to send the data on the second instance. The server

  • 0

I am not able to send the data on the second instance. The server just waits infinitely for client data
Here is my sample server code snippet:

ServerSocket serv = new ServerSocket(6789);
    Socket soc = serv.accept();
    System.out.println("waiting for client's input");       
    BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    DataOutputStream out = new DataOutputStream(soc.getOutputStream());
    String indata=in.readLine();
    System.out.println("The client says: "+indata+"\n Send them some data: ");
    String datum="demodata";        
    out.writeBytes(datum);
    System.out.println("Data sent");

Sample Client:

ocket soc = new Socket("localhost",6789);

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    DataOutputStream out = new DataOutputStream(soc.getOutputStream());     
    System.out.println("Connected to: "+soc.getLocalAddress() +"\nEnter data to be sent: ");        
    String outdata = br.readLine(); //take input    
    out.writeBytes(outdata); // send 
    String indata=in.readLine(); //read
    System.out.println("Data Sent! Now reading data from server "+indata)

Please tell me my problem! Thanks in advance

  • 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-29T23:54:35+00:00Added an answer on May 29, 2026 at 11:54 pm

    Answer is quite simple. You want to exchange lines of text between server and client.

    The correct part is on the server side:

    String indata=in.readLine();
    

    The wrong part is on the client side:

    out.writeBytes(outdata); // send 
    

    I haven’t tested the code, but it seems you are just sending some data and your server side waits for \n (newline escape sequence) to appear.

    Option 1:
    Construct a PrintWriter and call the corresponding println method.

    Option 2:
    Append a newline (\n) manually.

    Afterwards, readLine on the server side will recognize the line terminated by \n and will proceed.

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

Sidebar

Related Questions

I'm not able to connect a simple client and a simple server. When I
I am using Ajax POST method to send data, but i am not able
Why are we not able to override an instance variable of a super class
I am not able to flush stdin here, is there a way to flush
Experts, The following function are successfully send data to the Controller.cs (server) var ajaxResponse
I want to be a able to securely send data from my Android App
I want to modify GDLC MP4 Muxer so that it will not send data
I am not able to access localhost https pages in firefox3. It gave the
I am not able to use the breakpoint in Studio with Javascript. I'm able
I am not able to figure out this simple thing in ASP.NET MVC: I

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.