This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes messages sent via sockets get truncated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "messages sent via sockets get truncated" Watch "messages sent via sockets get truncated" New topic

messages sent via sockets get truncated

carl jensen

Joined: Nov 08, 2000
Posts: 11
I am trying to send large messages (~60,000 bytes) over sockets. For some reason, my messages always get truncated at 15,392 or 15,840 bytes. Can anyone help? Here is sample of my code:
public void run()
int bytesAvailable = in.available();
while(bytesAvailable == 0) {
try {
bytesAvailable = in.available();
catch(InterruptedException ie) {
// Read 8 1-K packets for a total of 8K message
byte[]b = new byte[(1024 * 8)];
int readCount = 0;
int offSet = 0;
StringBuffer sb = new StringBuffer();

while((readCount =,0,b.length))!= -1)
if(readCount < 8192)
sb.append(new String(b,0,readCount));
sb.append(new String(b));
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
I don't see anything wrong with your code here. I have heard of this problem occuring if your URL string doesn't exactly match the case of the URL for the server, check that. If your still having this problem, let us know.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
subject: messages sent via sockets get truncated
It's not a secret anymore!