This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Socket channel gets first reads data and all subsequent calls return 0?

Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to establish a SSL connection to a site and return its full response back. For some reason no matter what SSL site I go to when I step through the code it seems like the first read grabs a chunk of data and all subsequent calls return 0. I did some research and it appears there are two cases you would get back an int value of 0 from a read:

1. The server is busy ,lag with internet,etc - I do not think this is the issue because the loop calls read for a good 60 seconds during that time always returns 0.

2. The ByteBuffers passed into read are full and therefore cannot be written to - When looking at buffer I added a capacity of 100000. This is well below the possible response being added. I can tell by the position that the buffer has plenty of room in it? This appears to be a problem with a number of sites I have tried so I know its not an isolated server issue. I was hoping someone could glance at my securesocket class see if you can see any blatant issue that I'm overlooking that could be causing the problem:

Most importantly the read command. I believe the establishing of the connection is working because i'm getting data back from server. It's just never the full response.

A few things I'm seeing:

my request to on first read returns the headers as seen below. Then I pass that data to the response handler that checks the response notices its not complete goes back and calls again. All subsequent calls get a result of 0 back but I know there is more content maybe the content of the response? I'm just perplexed as to what I'm doing wrong.

In other sites I get even more of the response but never seems to get everything. In most cases after initial read everything is 0.

HTTP/1.1 200 OK
Date: Thu, 12 May 2011 04:17:50 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Server: gws
Content-Length: 9008
X-XSS-Protection: 1; mode=block

steve labar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ended up being that SSLResult when returned needs to call unwrap multiple times in a loop to get the data. One call to unwrap does not give you the full contents of the response!
On top of spaghetti all covered in cheese, there was this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic