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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:51:21+00:00 2026-05-31T15:51:21+00:00

I have a Java TCP game server, I use java.net.ServerSocket and everything runs just

  • 0

I have a Java TCP game server, I use java.net.ServerSocket and everything runs just fine, but recently my ISP did a some kind of an upgrade, where, if you send two packets very fast for the same TCP connexion, they close it by force.

This is why a lot of my players are disconnected randomly when there’s a lot of traffic in game (when there is a lot of chance that the server will send 2 packets at same time for the same person)

Here is an example of what I mean:
If I do something like this, my ISP will close the connexion for no reason to both client and server side:

tcpOut.print("Hello.");
tcpOut.flush();

tcpOut.print("How are you?");
tcpOut.flush();

But it will work just fine if i do something like this:

tcpOut.print("Hello.");
tcpOut.flush();

Thread.sleep(200);

tcpOut.print("How are you?");
tcpOut.flush();

Or this:

tcpOut.print("Hello.");
tcpOut.print("How are you?");
tcpOut.flush();

This only started a couple of weeks ago when they (the ISP) did some changes to the service and the network. I noticed using Wireshark that you have to have at least ~150ms time between two packets for same TCP connexion or else it will close.

1)Do you guys know what is this called ? does is it even have a name ? Is it legal ?

Now I have to re-write my game server knowing that I use a method called: send(PrintWriter out, String packetData);

2)Is there any easy solution to ask java to buffer the data before it sends it to clients ? Or wait 150ms before each sending without having to rewrite the whole thing ? I did some googling but I can’t find anything that deals with this problem. Any tips or information to help about this would be really appreciated, btw speed optimisation is very crucial. Thank you.

  • 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-31T15:51:22+00:00Added an answer on May 31, 2026 at 3:51 pm

    You may create a Writer wrapper implementation to keep track of last flush call timestamp. A quick implementation is to add a wait call to honor the 150 ms delay between two consecutive flushes.

    public class ControlledFlushWriter extends Writer {
        private long enforcedDelay = 150;
        private long lastFlush = 0;
        private Writer delegated;
    
        public ControlledFlushWriter(Writer writer, long flushDelay) {
            this.delegated = writer:
            this.enforcedDelay = flushDelay;
        }
    
        /* simple delegation for other abstract methods... */
    
        public void flush() {
            long now = System.currentTimeMillis();
            if (now < lastFlush + enforcedDelay) {
                try {
                    Thread.sleep(lastFlush + enforcedDelay - now);
                } catch (InterruptedException e) {
                    // probably prefer to give up flushing 
                    // instead of risking a connection reset !
                    return;
                }
            }
            lastFlush = System.currentTimeMillis();
            this.delegated.flush();
        }
    
    }
    

    It now should be enough to wrap your existing PrintWriter with this ControlledFlushWriter to work-around your ISP QoS without re-writing all your application.

    After all, it sounds reasonable to prevent a connection to flag any of its packet as urgent… In such a condition, it is difficult to implement a fair QoS link sharing.

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

Sidebar

Related Questions

I'm implementing a java TCP/IP Server using ServerSocket to accept messages from clients via
I have a TCP server running on a machine. (implemented in Java). I need
I have server in c and client in java but it doesn't work. 1.
I have a Java Client which sends UTF-8 strings to a C# TCP-Server, I'm
I have an java application using Socket TCP/IP and GUI. Server always listens connection
I have a Java client that connects to a C++ server using TCP Sockets
I have a Java app, connecting through TCP socket to a server developed in
I have created a TCP server-client application in java which exchange periodic messages between
I have a java server that has to communicate over a TCP socket to
I have a Java server. Clients connect to server via TCP. Here is the

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.