flush socket buffer

Discussion in 'Perl Misc' started by u8526505@ms27.hinet.net, Aug 3, 2005.

  1. Guest

    I try to write my tcp client to send as many number of bytes as I want
    immediately but tcp will not send them until some criteria is met.
    After a search of this topic, the mostly mentioned solution is to use
    select and autoflush or $|. Another mentions using
    syswrite($sock,$buf,1) can work. I've tried all of them but they don't
    seem to work. I'm wondering is this a doable task? When we use Telnet
    client applications, they can send one character right after when we
    hit the keyboard. Does anyone know how they can do it? Thanks.
    , Aug 3, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > I try to write my tcp client to send as many number of bytes as I want
    > immediately but tcp will not send them until some criteria is met.
    > After a search of this topic, the mostly mentioned solution is to use
    > select and autoflush or $|. Another mentions using
    > syswrite($sock,$buf,1) can work. I've tried all of them but they don't
    > seem to work.


    They work for me.

    > I'm wondering is this a doable task?


    For me it is doable. Maybe for you it isn't doable. You certainly aren't
    off to a good start.

    > When we use Telnet
    > client applications, they can send one character right after when we
    > hit the keyboard. Does anyone know how they can do it?


    By writing the code that does it. Do you actually have code? Can we see
    it? For all we know, you tried to type "$|=1" and accidentally mispelled it
    as "Hey Diddle diddle the cat played the fiddle".


    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Aug 4, 2005
    #2
    1. Advertising

  3. Guest

    寫é“:


    > By writing the code that does it. Do you actually have code? Can we see
    > it? For all we know, you tried to type "$|=1" and accidentally mispelled it
    > as "Hey Diddle diddle the cat played the fiddle".


    below is my code snippet

    ####
    socket(SOCKET, PF_INET, SOCK_STREAM, $proto);
    connect(SOCKET, $paddr);
    select SOCKET;
    $|=1;
    print SOCKET 'AAA\n';
    print SOCKET 'BBB\n';
    print SOCKET 'CCC\n';
    ####

    what I want is that the string in each print statement will be carried
    as payload by a network packet. In this case I expect 3 packets to be
    sent. But in fact only 2 packets were sent, one carried 'AAA\n' and the
    other 'BBB\nCCC\n'.
    , Aug 4, 2005
    #3
  4. Guest

    wrote:


    > ####
    > socket(SOCKET, PF_INET, SOCK_STREAM, $proto);


    What is $proto set to, in your case?

    > connect(SOCKET, $paddr);
    > select SOCKET;
    > $|=3D1;
    > print SOCKET 'AAA\n';
    > print SOCKET 'BBB\n';
    > print SOCKET 'CCC\n';
    > ####
    >
    > what I want is that the string in each print statement will be carried
    > as payload by a network packet.


    Why do you want that?

    > In this case I expect 3 packets to be
    > sent. But in fact only 2 packets were sent, one carried 'AAA\n' and the
    > other 'BBB\nCCC\n'.


    My interpretation is that Perl sent both BBB\n and CCC\n while the
    kernel/socket-layer was still dealing with the processing AAA\n. Once it
    was done with AAA\n, it loooked and found both BBB\n and CCC\n in its
    buffer and so sent both of them.

    And from a previous message:

    : When we use Telnet
    : client applications, they can send one character right after when we
    : hit the keyboard. Does anyone know how they can do it? Thanks.

    I don't think this is necessarily true. There is a tremendous difference
    between typing speed and CPU speed. If you look at it from the CPU's
    perspective, I bet the one character is sent a long time after the key is
    hit. Conversly, if your fingers could type as fast as Perl can print, I
    bet you would find more than one character per packet in a telnet session.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Aug 5, 2005
    #4
  5. yl Guest

    Hi,
    Thanks for all these responses. I have a more clear understanding about
    this topic now. I've used Net::packet to solve my problem after all
    since it can work on the packet level. The result is exactly as what I
    desired.
    yl, Aug 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian

    Response.Buffer and Resonse.Flush

    Brian, Nov 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,420
    Scott M.
    Nov 22, 2003
  2. Matthias Straka

    Minimum buffer length for Response.Flush?

    Matthias Straka, Sep 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    Matthias Straka
    Sep 9, 2004
  3. Kiran

    socket buffer flush question

    Kiran, Jul 5, 2006, in forum: Python
    Replies:
    2
    Views:
    974
    Jim Segrave
    Jul 5, 2006
  4. mike
    Replies:
    0
    Views:
    373
  5. Replies:
    1
    Views:
    1,920
Loading...

Share This Page