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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:23:46+00:00 2026-05-27T23:23:46+00:00

I have a very peculiar problem and my last resort was asking this on

  • 0

I have a very peculiar problem and my last resort was asking this on StackOverflow, so please be open minded!

Here are two programs:

A. Client: A java client running on an Android phone.
B. Server: A java server running on a Computer.

Here is what the two programs do:

Client sends server coordinates (in string format) every 2 milliseconds (very fast), and the server must read all those coordinates that the client sends it. In order to achieve this (given that the server is located at 10.0.0.1 and is listening on port 54321), the server must have a socket via which it reads all the incoming info. And yes, it does receive all of the information, BUT, there is a catch!

Now that you have the background behind the story, here is the problem:

The client connects to the server and as soon as that happens,it starts sending coordinates (in string format) at an extremely fast rate. The server does get all the messages, but it does not stop reading unless the client has disconnected. What i need is for the server to read every single message individually as they received!

Here is the code i used to read from the socket (this is for the server, and it is on its own thread):

    while(true) {
        try {
            BufferedReader socketReader = 
            new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String str = socketReader.readLine();
            System.out.println("New Message: " + str);
            socketReader.close();
        } catch (IOException e) {
            //Client disconnected
            System.out.println("Client disconnected.");
            break;
        }
    }

This is the output i am getting from the client (where x and y are numbers):

 New Message: x,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,yx,y...and so on

And that text only shows up AFTER the client has disconnected. I want it to show up AS THE MESSAGES come in.

Just to clarify, this is the desired output:

 New Message: x,y
 New Message: x,y
 New Message: x,y
 New Message: x,y
 ... and so on

In case this is of any use, here is the method of writing to the socket (this code is from the client)

PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
while(running) {
    writer = new PrintWriter(socket.getOutputStream(), true);
    writer.write(x+","+y);
    writer.flush();
}

So all in all, what i need is for my server to read the messages as they come in instead of reading them all at the same time after the client disconnects. P.S in C# i have also written a server and that one reads the info as it comes in, but in Java this isnt working out!

  • 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-27T23:23:47+00:00Added an answer on May 27, 2026 at 11:23 pm

    You are calling readLine which, as its name suggests, is for reading lines. Your data does not consist of lines.

    If possible, change your protocol so that each set of coordinates is terminated by a newline and/or carriage return.

    Unfortunately, I don’t think you’re going to be able to get this to work. 2ms resolution is just not possible over commodity network hardware and all kinds of things will break if you try to force it. If you enable Nagle, you’ll get 200ms delays from Nagling when an ACK is late. If you disable Nagle, dropping a data packet will shoot your latency through the roof.

    Honestly, I’d rip up the design and start over thinking through precisely what your requirements are and how you’re going to meet them.

    Where did you find an Android device that can send 500 packets a second?! No Wifi I know of can do that, and what use is GPS over a wire?

    (If you’re not already doing things like shrinking socket buffers to the absolute minimum, using non-blocking write operations, and handling partial writes by aborting and dropping partial data in the receiver, you won’t get anywhere close to meeting your requirements. You must not let data back up if there’s a momentary drop in connection bandwidth.)

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

Sidebar

Related Questions

I have a very peculiar problem. In the VS2010 Server Explorer, I can connect
I have a very peculiar problem across the IE board (ignoring IE6). Basically I
I am dealing with a very peculiar problem at the moment: I have an
I have a very peculiar problem:(not using web.config) DefaultFacebookApplication dfa=new DefaultFacebookApplication(); dfa.AppId = ...;
I have a very peculiar problem. I understand that while in the foreground the
I have a very peculiar problem on my hands. I have a project where
I have a very peculiar problem concerning formatted input buttons. On my first page,
I have very little to go on here. I can't reproduce this locally, but
Very peculiar problem here, Simply the background image asset will display fine on ALL
i have very serious problem if any tech expert can help...thank you in advance..

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.