recv() till particular string - Networking

This is a discussion on recv() till particular string - Networking ; Dear all, I have an application where the client receives message from server,but the problem is i need to receive message till a particular string arrives in the stream the client is getting.Is it possible to use recv() systems call ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: recv() till particular string

  1. recv() till particular string

    Dear all,

    I have an application where the client receives message from
    server,but the problem is i need to receive message till a particular
    string arrives in the stream the client is getting.Is it possible to
    use recv() systems call to do this or is there any other way.

    Please help me.


  2. Re: recv() till particular string

    Hi, Harry_1

    use a data-buffer, each time recv() returns, add-copy data to the buffer,
    then try find the "particular string" in the buffer (for performance
    consideration, you needn't find it from the head of the whole buffer each
    time);
    if found then return the data in the buffer.
    else select() for more data to read

    may it works, but a little hard to implementation.

    yours sincely

    Harry_2


    "Harry"
    ??????:1182499913.671881.78670@o11g2000prd.googleg roups.com...
    > Dear all,
    >
    > I have an application where the client receives message from
    > server,but the problem is i need to receive message till a particular
    > string arrives in the stream the client is getting.Is it possible to
    > use recv() systems call to do this or is there any other way.
    >
    > Please help me.
    >




  3. Re: recv() till particular string

    In article <1182499913.671881.78670@o11g2000prd.googlegroups.c om>,
    gehariprasath@gmail.com (Harry) writes:

    > I have an application where the client receives message from
    > server,but the problem is i need to receive message till a particular
    > string arrives in the stream the client is getting.Is it possible to
    > use recv() systems call to do this or is there any other way.


    Given a TCP/IP connection, recv() is the only way. Any routine that
    appears to be otherwise is merely a wrapper around recv(). There is
    no data sensitivity; the data is viewed as nothing more than a string
    of bytes, and recv() gets as much as it can. If you're looking for
    a particular string, there's not even a guarantee that one call to
    recv() will even receive all of it. For instance, if you're looking
    for "foo", the first time you call recv() you might just receive "fo".
    The next time you call recv() there might be nothing ready, and the
    third time you might finally receive the final "o" (plus any further
    bytes which might be coming through).

    So no, there is no simple solution. You'll have to write a routine
    that's smart enough to concatenate chunks of data, while checking
    whether the result contains what you're looking for. Take heart;
    it's not as hard as it seems.

    --
    /~\ cgibbs@kltpzyxm.invalid (Charlie Gibbs)
    \ / I'm really at ac.dekanfrus if you read it the right way.
    X Top-posted messages will probably be ignored. See RFC1855.
    / \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!


+ Reply to Thread