CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2005
    Posts
    13

    Question [VC 6] recv() issues, need help ^^""

    Hi everybody,

    During file receiving via recv(), is there any posibility that data received will lose?
    I am trying to receive a bitmap file via recv(), but the bitmap file I received seems to be corrupted and having different file size from original bitmap file, but I am able to receive txt file successfully without file corrupted issue.
    Can anybody help me solve this kind of problem?
    Best Regards,
    YL Koh

  2. #2
    Join Date
    Jan 2005
    Location
    Gothenburg, Sweden
    Posts
    134

    Re: [VC 6] recv() issues, need help ^^""

    Sure, post your code so that we can take a look.
    If you try and take a cat apart to see how it works,
    the first thing you'll have on your hands is a nonworking cat

  3. #3
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: [VC 6] recv() issues, need help ^^""

    Provided that you are sending and recving properly over a TCP connection, there is no chance that the data will be corrupted, missing or arriving out-of-order.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: [VC 6] recv() issues, need help ^^""

    But, you might not receive the data in one block. You need to do consecutively recv's until you know you received all of the data that has been sent to you.

  5. #5
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: [VC 6] recv() issues, need help ^^""

    That's right. It is because TCP is a stream protocol and don't preserve message boundaries. We have FAQs on the subject and how to avoid it.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  6. #6
    Join Date
    Jun 2005
    Location
    Buenos Aires, Argentina
    Posts
    66

    Re: [VC 6] recv() issues, need help ^^""

    Quote Originally Posted by Mathew Joy
    That's right. It is because TCP is a stream protocol and don't preserve message boundaries. We have FAQs on the subject and how to avoid it.
    Actually you normally would want an application level protocol to work on top of the TCP/IP protocol stack. That is, you must define a protocol (or implement an already defined protocol) to recognize message boundaries.

    I'll give you some application level protocols:
    1) Trivial length prefixed: the first four bytes of every message are always the size of the message body.

    2) Trivial with end flag: use some special char sequence (flag) to end the message. Of course, what would happen if that flag appears in the middle of the message? Well, you'll need to define an alternative sequence (escape) and do the following:
    a) If a (flag) appears in middle of the message put an (escape) before it.
    b) If an (escape) appears in middle of the message put an (escape) before it.
    When reading the message read until you receive a (flag) preceded by zero or an even number of (escape) sequences.
    Of course this is harder to implement but has no max size limit (in practice I doubt this is worth the effort).

    3) HTTP: a real life protocol. If uses a Content-Length: <body size> header, then a "\r\n\r\n" flag and then <body size> bytes of contents.

    I hope this clarifies a little.

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