Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Reading a txt file fastly Pin
«_Superman_»15-May-09 5:17
professional«_Superman_»15-May-09 5:17 
AnswerRe: Reading a txt file fastly Pin
Stuart Dootson15-May-09 5:20
professionalStuart Dootson15-May-09 5:20 
AnswerRe: Reading a txt file fastly Pin
David Crow15-May-09 7:00
David Crow15-May-09 7:00 
AnswerRe: Reading a txt file fastly Pin
Joe Woodbury15-May-09 17:53
professionalJoe Woodbury15-May-09 17:53 
QuestionRe-assembling TCP/IP Packets Pin
Koolski15-May-09 5:02
Koolski15-May-09 5:02 
AnswerRe: Re-assembling TCP/IP Packets Pin
led mike15-May-09 5:12
led mike15-May-09 5:12 
GeneralRe: Re-assembling TCP/IP Packets Pin
Rick York15-May-09 5:59
mveRick York15-May-09 5:59 
AnswerRe: Re-assembling TCP/IP Packets Pin
Robert Surtees16-May-09 2:21
Robert Surtees16-May-09 2:21 
First a book recomendation: Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs[^].

TCP is stream oriented. The order of the bytes going in one side always remains the same when it comes out the other side. At the application level there are no packets. Packets come into play after TCP gets your data and transmits it. It is free to do whatever is needed to get the bytes from one place to another -- split, combine, distribute amongst several homing pigeons, whatever. The bytes can arrive on the other side in any order but they are always reassembled in the sending order prior to presentation to the application.

I'm guessing you are sending messages of specific lengths over the socket and most of the time when you do a write on one side, your read on the other side gets the full message in one chunk. This is not always the case. When the receiver does a read(), all of the bytes in the stream may not have arrived yet and you will come up short or bytes from a following message may have arrived and you will get part of the next message. This is normal. You can't prevent it from happening. Assuming there is a one to one coorespondence between reads and writes is a very common mistake. It usually works when you are on the test bench but when things get busy, it all falls apart.

Typically what is done is to add some structure to your messages. Start them with some sort of Start of Message marker followed by the message length. The receiver reads this header portion and then reads again for the indicated length. The read may come up short in which you have to dip in again waiting for additional bytes. Once length bytes have been read, the next read should be for a message header again and the process repeats.
GeneralRe: Re-assembling TCP/IP Packets Pin
Koolski18-May-09 4:25
Koolski18-May-09 4:25 
QuestionDoes a Class having a message map need to be derived from CWnd ???? Pin
ForNow15-May-09 3:18
ForNow15-May-09 3:18 
AnswerRe: Does a Class having a message map need to be derived from CWnd ???? Pin
«_Superman_»15-May-09 5:11
professional«_Superman_»15-May-09 5:11 
GeneralRe: Does a Class having a message map need to be derived from CWnd ???? Pin
ForNow15-May-09 6:03
ForNow15-May-09 6:03 
GeneralRe: Does a Class having a message map need to be derived from CWnd ???? Pin
David Crow15-May-09 7:07
David Crow15-May-09 7:07 
GeneralRe: Does a Class having a message map need to be derived from CWnd ???? Pin
«_Superman_»15-May-09 20:36
professional«_Superman_»15-May-09 20:36 
GeneralRe: Does a Class having a message map need to be derived from CWnd ???? Pin
ForNow16-May-09 15:37
ForNow16-May-09 15:37 
QuestionRe: Does a Class having a message map need to be derived from CWnd ???? Pin
David Crow15-May-09 7:12
David Crow15-May-09 7:12 
AnswerRe: Does a Class having a message map need to be derived from CWnd ???? Pin
ForNow15-May-09 8:58
ForNow15-May-09 8:58 
QuestionHi.How to Include English dicitionary in visual c++ Pin
Sakthi.Gs :-)15-May-09 2:44
Sakthi.Gs :-)15-May-09 2:44 
AnswerRe: Hi.How to Include English dicitionary in visual c++ Pin
bolivar12315-May-09 3:13
bolivar12315-May-09 3:13 
GeneralRe: Hi.How to Include English dicitionary in visual c++ Pin
CPallini15-May-09 3:22
mveCPallini15-May-09 3:22 
GeneralRe: Hi.How to Include English dicitionary in visual c++ Pin
Maximilien15-May-09 3:58
Maximilien15-May-09 3:58 
GeneralRe: Hi.How to Include English dicitionary in visual c++ -- ITS URGENT Pin
bolivar12315-May-09 5:39
bolivar12315-May-09 5:39 
AnswerRe: Hi.How to Include English dicitionary in visual c++ Pin
Stuart Dootson15-May-09 5:15
professionalStuart Dootson15-May-09 5:15 
AnswerRe: Hi.How to Include English dicitionary in visual c++ Pin
Michael Schubert15-May-09 6:02
Michael Schubert15-May-09 6:02 
QuestionRe: Hi.How to Include English dicitionary in visual c++ Pin
David Crow15-May-09 7:15
David Crow15-May-09 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.