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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:36:33+00:00 2026-06-16T23:36:33+00:00

Im unable to get data in server from client using java Following is my

  • 0

Im unable to get data in server from client using java
Following is my server code :

 public void UpdateClients() throws Exception{

    Socket socktmp=null;

    try
    {
        socktmp= mainSocket.accept();
        rdr= new BufferedReader( new InputStreamReader(socktmp.getInputStream()));
        String t="";
        String name="";
        while((t=rdr.readLine())!=null){     <<<<< **it stops here**
            name=t;
        }
        //rdr.close();
        LstClient.AddClient(name, socktmp);

        objwriter = new ObjectOutputStream(socktmp.getOutputStream());
        objwriter.writeObject(LstClient.clients);
        objwriter.flush();  
        objwriter.close();
   }
   catch(Exception ex){
        throw new Exception("Unable to Update Clients. Error :" + ex.getMessage());
   }
      finally{
        try{
            if(mainSocket!=null){
                mainSocket.close();
            }
            if(socktmp!=null){
                socktmp.close();
            }
            if(rdr!=null)
            {
                rdr.close();
            }
            if(objwriter!=null)
            {
                objwriter.close();
            }

        }
        catch(Exception ex1){
            throw new Exception("Unable to close streams after opeining. Error :"+ ex1.getMessage());
        }


   }


}

and following is my client code:

public Client(String serverIp,int port,String name) throws Exception{

    try{
        if(mainSock!=null){
        mainSock.close();
        }
        mainSock= new Socket(serverIp, port);
        writer= new BufferedWriter(new OutputStreamWriter(mainSock.getOutputStream()));

        writer.write(name);
        writer.flush();
        **//writer.close();**
        Thread.sleep(1500);
        objin = new ObjectInputStream(mainSock.getInputStream());
        Hashtable<String,Socket> lst= new Hashtable<String , Socket>();
        lst = (Hashtable<String, Socket>) objin.readObject();
        cl = new LstClient();
        LstClient.clients = lst;
        System.out.println(LstClient.clients.size());
        objin.close();

    }
    catch(Exception ex){
        throw new Exception("Error : "+ ex.getMessage());
    }
    finally{
        if(mainSock!=null){
            mainSock.close();

        }
        if(writer!=null){
            writer.close();
        }
        if(objin!=null){
            objin.close();
        }


    }

}

I only get data in server or cursor goes on reading line on server side when i close writer in client end. but when i try to read after closing the writer at client end it says socket is closed so without closing it pauses on readline on server end
please help

  • 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-16T23:36:34+00:00Added an answer on June 16, 2026 at 11:36 pm

    I very common mistake when using readLine, is to forget to send a new line.

    You are sending text without a new line i.e. \n but waiting for it to be sent all the same.

    Try adding write('\n');

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

Sidebar

Related Questions

I have the following code on the client side for retrieving data from the
i am unable to parse data from server using json i am getting data
When I try to EDIT a tennis court... I get this exception :System.Data.UpdateException; Unable
I have the following code and I am still unable to get Hibernate to
I have a problem with sending ArrayList from server to my client using JAX-rs.
I'm sending bulk data to client from my C# server application. Different clients may
I have this code to connect to mysql and get data from one table
I'm unable to get the length of the following JSON array object. Actually I
I use Matlab's Database Toolbox to extract data from a SQL Server database. Today
I'm using TCP socket connetion between a server program and a client program. Multiple

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.