CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    398

    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.

  2. #2
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    398
    yalla help me ,its a yes or no question.
    Vision.

  3. #3
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Unless there is a network hickup, I would think it would come as one.

  4. #4
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    398
    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.

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  6. #6
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    398

    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.

  7. #7
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    398
    plz advice.
    Vision.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured