socket flush
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: socket flush

  1. #1
    Join Date
    Nov 2005
    Posts
    102

    socket flush

    I have a java application which must send strings back to a client. Now this works pretty good but in one function i have to send multiple string sepperatly so i thought i use a flush under every println() but that didn't work to well.

    Suppose im trying to send the following, one by one:

    Code:
            sendToClient.println("order_in:"+orderIn);
            sendToClient.flush();
    
            sendToClient.println("order:"+order);
            sendToClient.flush();
    
            sendToClient.println("beer_in:"+beerIn);
            sendToClient.flush();
    
            sendToClient.println("beer:"+beer);
            sendToClient.flush();
    
            sendToClient.println("beer_out:"+bierUit);
            sendToClient.flush();
    
            sendToClient.println("period:"+period);
            sendToClient.flush();
    I expected that this should send a string to the client one by one but thats not the case.
    I only get the first line sepperate from the rest: order_in:5
    and the rest comes in as one big message... Anyone any idea why this is happening..??

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: socket flush

    Give us a clue - what type is 'sendToClient' ?

    It's easy to cry "bug" when the truth is that you've got a complex system and sometimes it takes a while to get all the components to co-exist peacefully...
    D. Vargas
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    May 2008
    Posts
    5

    Thumbs up Re: socket flush

    i dont know what is 'sendToClient' , still i assuming its OutputStream..

    and definition of flush is that :


    The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.
    Point to Consider:If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.



    So i can say that your operating system is smart enough to send as buffer , rather than sending single single string to client.. which is inefficient..

    may be you should use some..separator between strings if u like.. i hope it will solve your problem.. good luck
    Last edited by honey_pisces; May 30th, 2008 at 12:17 AM.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: socket flush

    Quote Originally Posted by honey_pisces
    may be you should use some..separator between strings if u like..
    Good point - there is already a useful separator - the newline appended by println(..).

    The cheapest, fastest, and most reliable components of a computer system are those that aren't there...
    G. Bell
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center