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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:39:35+00:00 2026-05-23T01:39:35+00:00

I’m using a Socket to communicate with a ServerSocket. Strings are being sent from

  • 0

I’m using a Socket to communicate with a ServerSocket. Strings are being sent from the server to my Socket. Each distinct line is a message that, when parsed, contains information. To read these lines of text, a Scanner is used.

The problem is that data is coming in “spurts.” Although the Server is sending data continuously and evenly, the data read by the Scanner on the client side seems to pause, read in a bunch of messages (30-40) at once, and then pause again. It repeats this cycle indefinitely.

If I increase the rate at which data is sent, the duration of the pauses decreases; if I slow down the data (to 1 message per second), the bug persists and the pauses become very long. It’s almost as if the Socket waits for its buffer to overflow before it sends any data to the Scanner; then flushes everything and waits for the overflow again. However, if I decrease the size of the Socket’s buffer, nothing changes at all.

It should be noted that I’ve used Scanner and Socket in this method before – from the Server side – and everything worked as desired. Additionally, I a) tried this with a BufferedReader like the Java Tutorials (no change in the bug) and b) printed a list of Server transmissions into a file, and read from the file in the same way, and the program worked as expected (constant rate of message reception, etc) so the problem seems to be in the Socket itself.

So: How do I fix this behavior? I’m out of ideas atm and I really don’t know what’s going on.

CODE (As requested):

// In try block
// Makes the connection
Socket connection = new Socket(TARGET_MACHINE, PORT_NUMBER);
Scanner reader = new Scanner(connection.getInputStream());

// In new Thread
// In run()
while(!finished) // Boolean exit strategy
{
    if(reader.hasNextLine())
        Sring message = reader.nextLine();
}

That’s how I connect and retrieve the Strings.

Also, the Strings that I am receiving are usually about 20-40 characters long.

  • 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-23T01:39:36+00:00Added an answer on May 23, 2026 at 1:39 am

    Do you flush the stream every time you write to it from the server side? It could be buffering the output and not writing it to the stream until it reaches a certain threshold.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
In order to apply a triggered animation to all ToolTip s in my app,

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.