×
Namespaces

Variants
Actions
(Difference between revisions)

Mengatasi ‘Resource limit exceeded for TCP client sockets’ Exception pada Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Jeffrey.Halimsetiawan (Talk | contribs)
(Jeffrey.Halimsetiawan -)
 
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix metadata)
Line 9: Line 9:
 
|platform= Java ME
 
|platform= Java ME
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->  
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= HttpConnection, InputStream, TCP client sockets, Exception
 
|keywords= HttpConnection, InputStream, TCP client sockets, Exception
 
|language= Lang-Bahasa Indonesia
 
|language= Lang-Bahasa Indonesia
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate= <!-- Format YYYYMMDD -->
+
|creationdate= 20120928
 
|author= [[User:Jeffrey.Halimsetiawan]]
 
|author= [[User:Jeffrey.Halimsetiawan]]
 
}}
 
}}

Revision as of 03:58, 28 September 2012

Artikel ini akan menjelaskan bagaimana caranya untuk mengatasi 'Resource limit exceeded for TCP client sockets' Exception pada Java ME.

Article Metadata

Diuji dengan
Perangkat: Nokia N808 PureView, Nokia C3-00, Nokia Asha 300, Nokia N8-00

Kecocokan
Platform(s): Java ME
Series 40
Symbian
Nokia Belle

Artikel
Kata Kunci: HttpConnection, InputStream, TCP client sockets, Exception
Created: Jeffrey.Halimsetiawan (28 Sep 2012)
Perubahan Terakhir: hamishwillee (28 Sep 2012)

Pendahuluan

Saat mengembangkan sebuah aplikasi Java ME yang melakukan koneksi ke server menggunakan TCP client sockets atau kelas HttpConnection, suatu saat mungkin saja anda akan dihadapkan dengan permasalahan dimana muncul java.io.IOException: Resource limit exceeded for TCP client sockets. Permasalahan ini sebenarnya dapat diatasi dengan mudah dan biasanya diakibatkan oleh kelalaian namun akan berakibat sangat fatal.

Solusi

Penyebab dari permasalahan ini sangatlah sepele, yaitu:

  1. HttpConnection yang sudah di-open ke server, tidak di-close.
  2. InputStream atau OutputStream yang berada pada HttpConnection tersebut tidak di-close.

Jika Stream dan Connection tidak ditutup dengan benar, maka keduanya akan tetap terbuka. Semua perangkat mobile memiliki batas seberapa banyak koneksi yang dapat dibuka pada suatu waktu sehingga jika keduanya tetap dibiarkan dalam keadaan terbuka maka perangkat mobile tersebut akan kehabisan kuota untuk melakukan koneksi.

Caranya sangatlah mudah namun hal ini sangatlah krusial:
HttpConnection conn = (HttpConnection) Connector.open(url);
InputStream is = conn.openInputStream();
...
is.close();
conn.close();

Semoga bermanfaat!

75 page views in the last 30 days.
×