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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:47:37+00:00 2026-06-14T17:47:37+00:00

I have java server that I am writing the server reads command from clients,

  • 0

I have java server that I am writing the server reads command from clients,

the client written in C# sends command via socket in the form of json string.
The command looks like this

{
 "command": "blah",
 "key1": "value1",
 "key2": "value3",
 "key3": "value4",
}

The json string could have different number of key-val pairs every time, so there is no static count as such to measure number of lines in json command.

Here is how C# client sends json string to java server

        String json = JsonConvert.SerializeObject(map, Formatting.Indented);            
        streamWriter.WriteLine(json);
        streamWriter.Flush();

I want to read json this in the java code written in android. it looks something like as shown below, it reads the json lines properly but it blocks after reading last line of json command I am not sure what is the decent way to know that command has ended ..

        serverSocket = new ServerSocket(4444);   
        clientSocket = serverSocket.accept();
        InputStream inStream = clientSocket.getInputStream();           
        InputStreamReader inStreamReader = new InputStreamReader(inStream);          
        BufferedReader buffReader = new BufferedReader(inStreamReader );    

        String input = "";                        

        while((input = buffReader.readLine())!= null)
        {
            command += input;                     
        }

             //Does not get to this point, blocks above on the readLine after reading full json..

        JSONObject jsObj = new JSONObject(input);
        Object ovj = jsObj.get("command");  

I know may be I can send number of lines before sending json and read that many times in a while loop ? but that looks like a dirty solution, please advise what’s the right way to do it.

Thanks,
Ahmed

  • 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-14T17:47:38+00:00Added an answer on June 14, 2026 at 5:47 pm

    if you remove Formatting.Indented, every buffReader.readLine() will return you a different(complete) json. Move your deserialization code into the while loop.

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

Sidebar

Related Questions

I have developed a Java server using Eclipse that accepts TCP socket connection from
I have the following Java socket client app, that sends same string to socket
I have coded a server in Java that will have several clients connected to
I have the following code that reads response from a POP server through Sockets
I have a Java applet that streams video (MJPEG) from a server. I wrote
I'm writing a Java class that connects to a server and reads messages in
I am writing a server application in Java. To read from the socket i
I am writing a Google App Engine (Java) application that reads data from a
Im writing a client/server app for android that sends a username and password to
I have a java JAR file that is triggered by a SQL server job.

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.