Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 23
Registered: ‎04-29-2009
My Device: Not Specified

SocketConnection limitations??

So I'm working on Arr SS, an RSS Reader, and I've been trying to implement podcast support, but so far I've not found a way to download the large podcast files.  The first problem that I've run into is that when I pass a socketconnection a url that does a redirect I'm getting nothing back from the server....with a packet sniffer I see that the dns name is being properly resolved, but that's about as far as it goes.  If I use a URL that does no redirect then it works, but only on really small files....I suspect I'm hitting the berry's transfer limitation, however I was under the impression that SocketConnections did not have this limitation.  Any ideas on how to get around the problem?  The only thing I've seen actually work is if I pass the url to a high performance web service and have it split the mp3 data up into smaller junks, but I don't make enough money to cover the cost of maintaining the web service.

 

Code looks similar to:

 


InputStream is = null;
OutputStream os = null;
String url = RequestUrl(); //pass in a standard url

//setup and open a file connection on the SD card
if(!setupFile() || fileOs == null) return;

//clean up the url so I can use it for socketconnection
String cleanUrl = url;
if(url.indexOf("://") > 0)
cleanUrl = url.substring(url.indexOf("://")+3);

String domain = cleanUrl;
String path = "";
if(cleanUrl.indexOf("/") > 0) {
domain = cleanUrl.substring(0, cleanUrl.indexOf("/"));
path = cleanUrl.substring(cleanUrl.indexOf("/"));
}

try {
c = (SocketConnection) Connector.open("socket://" + domain + ":" + (url.toLowerCase().startsWith("https") ? "443" : "80") + Util.getConnectionSuffix(), Connector.READ_WRITE, true);
os = c.openOutputStream();
//do I pass the url or only the path, RFC says the path, packet sniffers on IE & FF show the full url????
os.write(("GET " + url + " HTTP/1.0\r\n").getBytes());
os.write(("Host: " + domain + "\r\n").getBytes());
os.write(("User-Agent: Arr!SS/1.5\r\n").getBytes());
os.write(("Connection: keep-alive\r\n").getBytes());
os.write(("Accept: */*\r\n").getBytes());
os.write(("\r\n").getBytes());
is = c.openInputStream();
byte[] buffer = new byte[16128];
int result = is.read(buffer);
while (result != -1) {
fileOs.write(buffer,0,result);
result = is.read(buffer);
}
os.flush();
cleanUpSocketAndFileConnection();
} catch....
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: SocketConnection limitations??

[ Edited ]

What happens when you pass a non-redirecting URL and a big file is supposed to be sent back? Are you getting anything back at all?

 

P.S. I suggest you call os.flush() after the last os.write() (before opening the input stream). This will explicitly make sure that whatever you wrote into the output stream gets to the network stack (and hence the HTTP server) before you start waiting for something to come back from the server. Otherwise you could end up in a situation where you are waiting for data from the server (HTTP response) while the server is waiting for data from you (HTTP request).

 

P.P.S. Try your code on a socket connection via WiFi to eliminate the additional unknowns of MDS, BIS-B, and various carrier gateways that may be influencing the result.

Message Edited by klyubin on 09-03-2009 08:38 PM
New Developer
Posts: 23
Registered: ‎04-29-2009
My Device: Not Specified

Re: SocketConnection limitations??

On small non-redirecting files I get back the file data, on large non-redirecting files I get back nothing.  Moving the os.flush around doesn't appear to make any difference (in regards to the problem I'm having).

 

-Ryan