| Reply | « Previous Thread | Next Thread » |
|
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... |
|
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 |
|
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 ..... |
|
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 |
| anand_amarsh |
| View Public Profile |
| Find all posts by anand_amarsh |
|
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... |
|
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. |
| anand_amarsh |
| View Public Profile |
| Find all posts by anand_amarsh |
|
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. |
|
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) |
| anand_amarsh |
| View Public Profile |
| Find all posts by anand_amarsh |
|
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... |
| silviacipi |
| View Public Profile |
| Find all posts by silviacipi |
|
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 |
|
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!!! |
| silviacipi |
| View Public Profile |
| Find all posts by silviacipi |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
Offline
Super Contributor
|
|
hi,
is your "close()" (closing routine) enclosed with try/catch so you can see if IOException occurs (if any)? regards, Peter |
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|