|
-
November 19th, 2003, 02:34 PM
#1
J2ME-DataInputStream question
Im using the J2ME platform , the only way to read strings is by the class DataInputStream.readUTF();
my question is :
if the server side sends a large String (theoreticly -unlimited)
will it arrive as one String ?
or i need to check over and over if data still keeps comming and append it to my String ?
because as for now im just calling the method .
Vision.
-
November 20th, 2003, 06:06 AM
#2
yalla help me ,its a yes or no question.
Vision.
-
November 24th, 2003, 06:03 PM
#3
Unless there is a network hickup, I would think it would come as one.
-
November 24th, 2003, 07:24 PM
#4
so you mean ,if i send one mega for example ,ill wait till the mega arrives and then it will showup in one string?
Vision.
-
November 25th, 2003, 06:16 AM
#5
Originally posted by Ishaibin
so you mean ,if i send one mega for example ,ill wait till the mega arrives and then it will showup in one string?
http://jsr82.devzone.possio.com/cdc/...t.html#readUTF()
seems to imply that the first 2 bytes give an indication as to the length of the string, which places a theoretical maximum read on the string of 65536 bytes. unless, of course, the first two bytes indicate the cahracter length, then given that the string is in unicode, the bytes read will be 65536*2, and the characters read will be 65536. (max)
i believe the underlying implementation deals with this, though what precisely it does if the serving application sends no information as to the length of the string, i do not know
-
November 27th, 2003, 09:49 AM
#6
Design Consulting:
Hi!
My sever may send a large packets of data using DataOutputStream, and i want the client to be able to abort from the sending in the middle if it takes too much time.
So what i want to do is to add a special flag in the method and then when the clients send a special token the flag will be raised and the server will abort from the sending.
this is my design for it :
I have a connection class -when ever a client connects the server creates a new connection object that is also a thread.
the connection recieves data ,process it using ProcessData object and returns it to the client.
In order to be able to reiceve the abort token i consider to create another thread in a private class inside the Connection class that will then again listen to the inputstream and recieve the speical token if it is sent.
then ,i also need to add the flag,
i tracked the writeUTF(String s) method in the DataOutputStream object and saw that in the end of the encoding it sends its bytes using a method it recieves from FilterOutputStream
in this method :
Code:
public void write(byte b[], int off, int len) throws IOException {
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
throw new IndexOutOfBoundsException();
for (int i = 0 ; i < len ; i++) {
write(b[off + i]);
}
}
so basicly i need to add the flag to the for loop .
so what im going to do is to extend the FilterOutputStream class in a private class in the Connection Class and override that method adding the flag .
then im going to extend that private class with another private class which will add the writeUTF() functionallity -taken from the DataOutputStream class in the old fushiond copy&paste way (kill bill)
The second private class is no longer DataOutputStream by any chance ,its just a class that supports writing Strings so i feel like im moving into deep water around here as im not sure what exactly happens behind stage when the communication takes place.
what do you think of my design ?
including the abort thread listener and the outputstream abort flag functionallity ?
do you have any better design that i can use ? cuz this seems a little off bounds .
but ofcourse i will use it if ill have to.
what bothers me even more is how do i avoid exceptions on the client side when the server suddenly stops sending data ?
also i want to add a Gauge that will show how much has been completed.
for that im going to extend the DataInputStream on the client side and count how much data recieved ,then add a status method that will simply return me a double precentege number.
Thank You !
Vision.
-
November 27th, 2003, 05:58 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|