Click here to Skip to main content
16,006,605 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionTCP receive 2 Pin
Archyami18-Oct-06 18:39
Archyami18-Oct-06 18:39 
AnswerRe: TCP receive 2 Pin
mpk197918-Oct-06 20:34
mpk197918-Oct-06 20:34 
GeneralRe: TCP receive 2 Pin
Archyami18-Oct-06 20:43
Archyami18-Oct-06 20:43 
AnswerRe: TCP receive 2 Pin
Mark Salsbery19-Oct-06 5:51
Mark Salsbery19-Oct-06 5:51 
GeneralRe: TCP receive 2 Pin
Archyami19-Oct-06 15:35
Archyami19-Oct-06 15:35 
GeneralRe: TCP receive 2 [modified] Pin
Mark Salsbery19-Oct-06 16:26
Mark Salsbery19-Oct-06 16:26 
GeneralRe: TCP receive 2 Pin
Archyami20-Oct-06 6:00
Archyami20-Oct-06 6:00 
GeneralRe: TCP receive 2 Pin
Mark Salsbery20-Oct-06 10:08
Mark Salsbery20-Oct-06 10:08 
Archyami wrote:
1. The message eg. equals "abc". Its length is 3.
Why should I send its length as 4?
(The server is checked to send data within the length of CATOS_BUFFER_SIZE.)


I don't think you SHOULD send 4. I was just trying to fix your exception before. If you
have 3 bytes to send then send 3 bytes Smile | :)

Archyami wrote:
2. The recv buffer is allocated with 1 more byte for safe (may be it is a risk...)
My design is that if CATOS_BUFFER_SIZE==10 and message comes from the server as "1234567890", it can hold the message. Indeed, a terminator is at the end (here is '0'). If '\0' is padded by the server, it can still hold the message.
'\0' is padded automatically for initializing an char array.
Please advise if my analysis is wrong.


If you want to send the '\0' WITH the string of characters "1234567890" then you need to
send 11 bytes. It is up to YOU to send and receive the correct amount of bytes.


Archyami wrote:
3. If the server is checked to send data within the length of CATOS_BUFFER_SIZE, is it possible that the client recv() may receive the message sereral times instead of once?
I mean: recv() holds the application (thread). 'several times' refers to 1 recv() receives a part of the message, several recv() receives all message 'packages'.


I'll try to explain this again...TCP knows NOTHING about "packages" or "packets" - it only
knows a STREAM of bytes. You can send 1000 bytes and on the other end you may receive
all 1000 bytes in one call to recv(), you may receive 10 bytes in one call to recv() and
990 bytes in the next call to recv(), etc.. It's all about BYTES and it's up to you keep
calling recv() until you get the number of bytes you are expecting.

If you always want to recv the same number of bytes you send then you need to use a
message/datagram based protocol like UDP.

I suggest reading this Windows Sockets 2[^].

Mark
QuestionHow to add a worksheet in excel Pin
Abhiyantara18-Oct-06 17:32
Abhiyantara18-Oct-06 17:32 
AnswerRe: How to add a worksheet in excel Pin
Hamid_RT18-Oct-06 18:17
Hamid_RT18-Oct-06 18:17 
Questionproblem with atl new wizard Pin
With_problem18-Oct-06 17:16
With_problem18-Oct-06 17:16 
AnswerRe: problem with atl new wizard Pin
Hamid_RT18-Oct-06 18:21
Hamid_RT18-Oct-06 18:21 
QuestionRe: problem with atl new wizard Pin
David Crow19-Oct-06 4:27
David Crow19-Oct-06 4:27 
Questionclass which has no .cpp and .h Pin
gentleguy18-Oct-06 16:29
gentleguy18-Oct-06 16:29 
AnswerRe: class which has no .cpp and .h Pin
Waldermort18-Oct-06 18:57
Waldermort18-Oct-06 18:57 
AnswerRe: class which has no .cpp and .h Pin
Hamid_RT18-Oct-06 19:27
Hamid_RT18-Oct-06 19:27 
AnswerRe: class which has no .cpp and .h Pin
David Crow19-Oct-06 4:28
David Crow19-Oct-06 4:28 
GeneralRe: class which has no .cpp and .h Pin
David Crow19-Oct-06 4:52
David Crow19-Oct-06 4:52 
GeneralRe: class which has no .cpp and .h Pin
Jonathan [Darka]19-Oct-06 4:53
professionalJonathan [Darka]19-Oct-06 4:53 
AnswerRe: class which has no .cpp and .h Pin
Jonathan [Darka]19-Oct-06 4:54
professionalJonathan [Darka]19-Oct-06 4:54 
QuestionCListCtrl dissapearing image Pin
P1P3R18-Oct-06 13:21
P1P3R18-Oct-06 13:21 
AnswerRe: CListCtrl dissapearing image Pin
Mark Salsbery18-Oct-06 14:06
Mark Salsbery18-Oct-06 14:06 
GeneralRe: CListCtrl dissapearing image Pin
P1P3R19-Oct-06 6:04
P1P3R19-Oct-06 6:04 
AnswerRe: CListCtrl dissapearing image Pin
Michael Dunn18-Oct-06 16:17
sitebuilderMichael Dunn18-Oct-06 16:17 
GeneralRe: CListCtrl dissapearing image Pin
P1P3R19-Oct-06 6:06
P1P3R19-Oct-06 6:06 

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.