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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:22:24+00:00 2026-05-27T22:22:24+00:00

I have this TCP server running Because UDP server was able to accept large

  • 0

I have this TCP server running Because UDP server was able to accept large packets but ISP blocks my UDP packets even i have Public IP and Static services. But now decided to change it to TCP but i have a large stack now to replace with UDP to TCP.

Here is the server which is running but it does not at once receive a large packet, how can i increase it to unlimited or maximum size or etc?

1) Is there any way with this?

public void run() 
{
    while(true) 
    {
        byte[] buf=new byte[5024]; <<< not helping!!
        int bytes_read = 0;
        try {                                
            bytes_read = sockInput.read(buf, 0, buf.length);                  
            String data = null;
            data = new String(buf, 0, bytes_read);                   
            System.out.println("[TCP]: incomeing data: " +  bytes_read + " bytes, data=" +data);
     }
 }

2) Is there any way with this?

public TCPHandler(Socket sock) throws IOException 
{
    sock.setReceiveBufferSize(10*1024 +1024); //<<<<< not helping !!!
    sock.setSendBufferSize(10*1024+1024);
    this.sock = sock;
    sockInput = sock.getInputStream();
    sockOutput = sock.getOutputStream();
    this.myThread = new Thread(this);
}

None is allowing me to handle large so that i can switch from UDP to TCP. Any ideas!!

  • 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-27T22:22:25+00:00Added an answer on May 27, 2026 at 10:22 pm

    The trouble you’re having is how InputStreams work. When you call read(buf,offset,length) it doesn’t always read length bytes everytime. It simply reads what is available() on the InputStream, and returns the number of bytes it read. So you need to continue to call read until you’ve actually read length bytes.

    int len = 0;
    int expectedLength = sockInput.readInt();
    byte[] buf = new byte[ expectedLength ];
    while( len != buf.length ) {
       len += sockInput.read( buf, len, buf.length );
    }
    
    // now you have a buffer with expectedLength data in it.
    

    You can also look at using DataInputStream.readFully() by wrapping your

    DataInputStream ds = new DataInputStream( sock.getInputStream() );
    ds.readFully( buf, 0, buf.length );
    

    http://docs.oracle.com/javase/6/docs/api/java/io/DataInputStream.html

    But if you’re really just after a String you should do this:

    Reader reader = new InputStreamReader( sockInput.getInputStream(), "UTF-8" );
    

    Same rules for read( char[], offset, length ) as read( byte[], offset, length )

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

Sidebar

Related Questions

I have written a secure TCP server in .NET. This was basically as simple
I have a TCP server running on a machine. (implemented in Java). I need
I have a tcp client - server implementation running in the same program, on
I have a server running on Windows Azure here with a large key (link
i am using pcap to create a packet sniffer. i have this tcp structure:
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I have a tcp socket sending three lines like this out2.println(message1\n); out2.println(message2\n); out2.println(message3\n); and
I have one server and three clients in which a windows service is running
I have two programs written in C++ that use Winsock. They both accept TCP
I have a remote Music Player Daemon(MPD) server running on a linux machine. I

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.