You Are Here:

Community: Developer Discussion Boards

#1 Old Question Close HTTP Connection bug ??? - 2004-12-27, 08:25

Join Date: Dec 2004
Posts: 15
cars2004
Offline
Registered User
Hello,
Does anyone know how to close J2ME HTTP Connection on Nokia 6020.
I use this line to open HTTP Connection :
c = (HttpConnection) Connector.open (url2open.trim());
the connection successfuly opened, (marked with "G symbol in the box" in top left of the screen, meaning the GPRS connection is open)

But when I try to close the connection using:
c.close(), the G symbol is still exist (connection still open).

How to make the connection close in Nokia 6020?

Does anyone know? Help me please...

Thanks...
Reply With Quote

#2 Old 2004-12-27, 09:24

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
GPRS connections have a very high overhead when opening the connection, and after the connection is open they are quite fast. It is for this reason that when you close a connection, the implementation will keep the GPRS alive for a period of time, in case you want to make other connections, so you won't have to wait for the GPRS to start up again. This is something you have no control over with MIDP, and you shouldn't worry about it, since GPRS, unlike data calls, is charged by the amount of data you transfer and not by the time you are connected. If you wait around 30 seconds without making any more connections the GPRS will close.

shmoove
Reply With Quote

#3 Old 2004-12-27, 09:37

Join Date: Dec 2004
Posts: 15
cars2004
Offline
Registered User
hi shmoove,
thanks for your reply....
so, it seems that Connection.close is not useful in J2ME application.

I try to close the HTTp connection because
on the first connection, the phone show message "Allow network access?" but in second connection it never showed again. I think it is because the first connection is still alive and never closed. So if I want to show message "Allow Network access?" again, I have to exit from my app and start again :(

I need to close HTTP Connection when user press "Close Connection" button on my app. Can you or anyone help me?

Anyway, thanks for your answer shmoove...

Thanks .....
Reply With Quote

#4 Old 2004-12-30, 02:46

Join Date: May 2003
Posts: 47
anand_amarsh
Offline
Registered User
one reason why you should close the GPRS connection when not needed in the rest of the application is to let Garbage Collector clean it up. i have seen noticable improvements on MIDP1 modlets for series40 devices.
as for the "allow access" thingy, it has nothing to do with the MIdlet opening GPRS connection - its is a phone setting. On Nokia phones, you can avoid this on Nokia phones by turning the "Web Access" to "Allowed". This is how I do it on my phone :
Main Menu -> Applications -> Options -> Web Access -> Select -> Allowed
Reply With Quote

#5 Old Hmmm.... - 2004-12-30, 03:13

Join Date: Dec 2004
Posts: 15
cars2004
Offline
Registered User
Hi anand, thanks for your reply,
Yes, I have try to set the connection setting in my phone. But i think, if I try to assign my app on Java Verified Test, it will never pass :(
Because on the test, in the Network section, said :

"NT5 (R)
The application must be able to close the connection which it's using after
the session is over."

hmm....

I confuse about programming in Series 40 Device, I think it differ from Series 60. For example, it read RecordStore in reverse way, from the last data to the first data. But when I try in Series 60, it read data from the first to the last .

Do you know where I can find the document about the difference of programming in Series60 and Series40?

Thanks in advance...
Reply With Quote

#6 Old 2005-01-03, 02:36

Join Date: May 2003
Posts: 47
anand_amarsh
Offline
Registered User
sorry, i havent programmed any series 60 devices yet. i am writing an application for mass use, so i am trying to get it working on any device whatsoever. fortunately, i havent faced any discrepencies as yet (fingers crossed :)
as for record store, i used record enumerator and record filter, so i never ran into problems with the order of record store traversal.
Reply With Quote

#7 Old 2005-01-06, 11:52

Join Date: Jan 2004
Posts: 165
mreaves
Offline
Regular Contributor
You have closed the connection once you perform the close() command so don't worry about the Java verified thing.

Trust me, it is a good thing that the GPRS is active for a while after closing the connection because if you need it again then it will be much quicker to open a connection and get data if the GPRS link is already established.
Reply With Quote

#8 Old 2005-01-07, 07:46

Join Date: May 2003
Posts: 47
anand_amarsh
Offline
Registered User
i agree that GPRS connections remaining active for sometime is a blessing :)
on my application (which accesses about 8KB of XML file) on 2.5G network, the end to end access time for the first time is around 15s while the next access is aorund 8s (all this on series 40 phone)
Reply With Quote

#9 Old Close HTTP connection - 2006-08-25, 12:06

Join Date: Aug 2006
Posts: 2
silviacipi
Offline
Registered User
hi,
I have got this problem: I'm developing an application for nokia 6021.
I have to use a gsm connection and the problem is that I can't close it!
the command close() doesn't work!
Anyone can help me??

Thanks in advance...
Reply With Quote

#10 Old Re: Close HTTP connection - 2006-08-25, 15:13

Join Date: Dec 2005
Posts: 1,886
Location: Brazil
Send a message via MSN to juarezjunior Send a message via Skype™ to juarezjunior
juarezjunior's Avatar
juarezjunior
Offline
Forum Nokia Champion
Hi silviacipi,

"I have to use a gsm connection and the problem is that I can't close it!"
What do you mean by saying "gsm connection"?

I would help a lot if you provide your code for analysis.

BR,

Juarez Junior
Reply With Quote

#11 Old Re: Close HTTP Connection bug ??? - 2006-08-25, 16:15

Join Date: Aug 2006
Posts: 2
silviacipi
Offline
Registered User
Hi juarezjunior,

the code semplified is that:

DataInputStream httpInput = null;
DataOutputStream httpOutput = null;
httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
try
{
httpConnection.setRequestProperty("Excpect", ""); httpConnection.setRequestProperty("Content-Type","//text plain"););
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("Connection", "close");

httpOutput = httpConnection.openDataOutputStream();
httpOutput.write("//TO WRITE//");
httpOutput.flush();

httpInput = httpConnection.openDataInputStream();
nt length = (int) httpConnection.getLength();
if (length != -1)
{
byte incomingData[] = new byte[length];
inputstream.read(//incomingData//);
str = new String(//incomingData//);
}

}
catch (Exception ex)
{

}
finally
{

if (httpInput != null)
{
httpInput.close();
}
observer.trace("d");
if (httpConnection != null)
{
httpConnection.close();
}
}

the request and the response are correct, my problem is that: in nokia 6021 if I use GSM connectivity, the connection doesnt't close with the command httpConnection.close(); If that is not a problem with gprs connection,where you are charged by the amount of data you transfer, with gsm connection it is a problem because you are charged by the time you are connected.

How can I do?

Thanks in advance!!!
Reply With Quote

#12 Old Re: Close HTTP Connection bug ??? - 2006-08-26, 02:35

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
hi,

is your "close()" (closing routine) enclosed with try/catch so you can see if IOException occurs (if any)?

regards,
Peter
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia