|
-
July 28th, 2005, 03:35 AM
#1
[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
-
July 28th, 2005, 04:05 AM
#2
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
-
July 28th, 2005, 05:47 AM
#3
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
-
July 28th, 2005, 03:20 PM
#4
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.
-
July 28th, 2005, 11:09 PM
#5
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
-
July 29th, 2005, 12:22 PM
#6
Re: [VC 6] recv() issues, need help ^^""
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|