12-08-2009 09:30 PM
I am trying to create a SecureSocket connection on RIM device.and getting the response from the server.
I am trying to read InputStream from the socket connection, it is taking around 3mins to read complete response data.
Please help me; how I could resolve this.
Code sample is here:
String urlSSL = "ssl:.//" +get_host()+":"+get_Port()+";deviceside=true";
SecureConnection sc = (SecureConnection)Connector.open(urlSSL);
OutputStream os = sc.openOutputStream();
byte data =getDataToSend();
if(data != null)
//read from Socket
InputStream is = sc.openInputStream();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
boolean aReadingStatus = false;
byte buffer = new byte[bytesToRead];
while((is.read(buffer, 0, bytesToRead)) != -1)
aReadingStatus = true;
System.out.println("Exception in reading response");
aReadingStatus = false;
I have tried to read one bye one char too, but still the result is same.
while i am trying to do "is.read()" it took almost 3mins to read complete data and process next stmt.
Please let me know what I am doing wrong here.
12-09-2009 04:38 AM
Another issue is that you are the read method can read less that 1024 bytes, but you are always writing 1024 bytes into the output in every iteration of the loop...
12-09-2009 02:16 PM
First of all there was typing mistake "ssl:.//".. it is "ssl://" only in my code.
I have tried code with :
while(ch != -1)
ch = is.read();
if(ch != -1)
byte buffer = new byte[bytesToRead];
int readBytes = 0;
while((readBytes = (is.read(buffer, 0, bytesToRead))) != -1)
bout.write(buffer, 0, readBytes);
Still not taking time.
Please provide me the code, where I am doing wrong.
12-09-2009 08:39 PM
"Please provide me the code, where I am doing wrong."
However there is a lot of work to be done to determine where the problem actually is before anybody can suggest what changes you might consider.
Here are some questions that will help tie this problem down:
1) You say this process is taking 3 minutes - is this on the device or on the Simulator.
2) Have you tested this code on the Simulator? If you have not, please do. Do you see the same problem there?
3) How much data are you trying to send.
4) What connection method are you trying to use?
5) Have you attempted to get similar socket data from the Server from another platform (like a PC)? If not, can you try this. Does it take just as long?
12-13-2009 06:22 PM
1) I am testing on device.
2) Could not test on Simulator, because the data which I am sending calculated using device information.
3) The data I am sending alomost 300bytes.
4) I am using secure connection
I openned connection with "deviceside=true" with "ssl://", the protocol name returned from after connection as "TLS".
When I used "END_TO_END_REQUIRED" or "END_TO_END_DESIRED" it returns "SSL".
There is one more problem I am facing:
I want to write new data on same secure connection.
I have tried the following:
1. Open connection if it is null
2. Open output stream
3. Open input stream
4. Write data in OS
5. Read from IS.
6. Write data in same OS second time after sometime : Gives connectionclosed exception (I have not closed it yet)
If I closed OS and IS, and reopen OS it gives exception at secureconnection.openOutputStream(). IOException, connection closed.
How i could use the same SecureConnection to write data second time?
12-14-2009 02:53 PM
I would like to add one more thing.
I am getting the ConnectionCloseException while doing outputStream.flush().
Code is like:
if(isConnectionOpen == false)
// open SSLConnection
// Open output stream
// open inputstream
isConnectionOpen = true;
outputStream.flush(); // here I am getting conneciotn closed exception: Bad Socket ID while writing second time
//Reading from inputstream
I am not closing connection, the code for closing connection is called when 2nd time reading and writing completes.
Let me know any good solution for using same socket connection 2nd time to get response.
12-14-2009 05:52 PM
I have checked on server logs and as par logs the server closes the connection after 2min, and my application is taking longer time to send next request.
I have debug the code and log time in a log file.Most of the time is consuming by the application in reading first response data.
So I am again stuck on my first problem ie how do I make reading fast.