Click here to Skip to main content
15,900,511 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: TCP client/server data exchange Pin
Jörgen Sigvardsson14-Nov-07 21:35
Jörgen Sigvardsson14-Nov-07 21:35 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery14-Nov-07 11:41
Mark Salsbery14-Nov-07 11:41 
GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 3:03
JudyL_MD15-Nov-07 3:03 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 5:43
Mark Salsbery15-Nov-07 5:43 
GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 6:01
JudyL_MD15-Nov-07 6:01 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 6:30
Mark Salsbery15-Nov-07 6:30 
GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 6:52
JudyL_MD15-Nov-07 6:52 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 7:10
Mark Salsbery15-Nov-07 7:10 
JudyL_FL wrote:
Can you try calling WSAGetLastError after you receive the partial bytes?


Sure Smile | :)

WSAGetLastError() returns 0;

A long time ago, while writing some of my first communication code, I got bit by this (using pipes actually,
but it made me look at my sockets code) and it taught me to read the documentation thoroughly (which I
wasn't doing apparently Smile | :) ).  That's when I found this:

"For connection-oriented sockets (type SOCK_STREAM for example), calling recv will return as much data
as is currently available—up to the size of the buffer specified.
"

FWIW, This also applies to pipes.

So, any amount of bytes returned by recv() indicates success.  This can be seen especially when receiving
amounts larger than the socket buffer, where the protocol MUST return a buffer full of data to make room to
receive more.

This seems to be the number one thing overlooked by beginner socket programmers.


I studied MS's implementation of TCP a while back, and there is a timeout involved internally, but it's
not an error of any kind.  I believe by default it's 200ms (that's the number that comes to mind) before
a recv() returns what it has currently buffered.  That's what makes it inefficient to always request more
bytes than you're expecting.

Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 7:25
JudyL_MD15-Nov-07 7:25 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 7:36
Mark Salsbery15-Nov-07 7:36 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 7:14
Mark Salsbery15-Nov-07 7:14 
GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 7:27
JudyL_MD15-Nov-07 7:27 
GeneralRe: TCP client/server data exchange Pin
Mark Salsbery15-Nov-07 7:36
Mark Salsbery15-Nov-07 7:36 
GeneralRe: TCP client/server data exchange Pin
JudyL_MD15-Nov-07 2:59
JudyL_MD15-Nov-07 2:59 
QuestionWeird namespace alias resolution problem in VC++ 2003 Pin
Orhun Birsoy14-Nov-07 8:42
Orhun Birsoy14-Nov-07 8:42 
AnswerRe: Weird namespace alias resolution problem in VC++ 2003 Pin
Mark Salsbery14-Nov-07 9:30
Mark Salsbery14-Nov-07 9:30 
AnswerRe: Weird namespace alias resolution problem in VC++ 2003 [modified] Pin
snowfall114-Nov-07 16:39
snowfall114-Nov-07 16:39 
QuestionAppoint help: [modified] Pin
Hakan Bulut14-Nov-07 6:37
Hakan Bulut14-Nov-07 6:37 
AnswerRe: Appoint help: Pin
Janzen14-Nov-07 7:14
Janzen14-Nov-07 7:14 
GeneralRe: Appoint help: Pin
Hakan Bulut14-Nov-07 7:34
Hakan Bulut14-Nov-07 7:34 
GeneralRe: Appoint help: Pin
led mike14-Nov-07 7:48
led mike14-Nov-07 7:48 
GeneralRe: Appoint help: Pin
Mark Salsbery14-Nov-07 8:02
Mark Salsbery14-Nov-07 8:02 
GeneralRe: Appoint help: Pin
Hakan Bulut14-Nov-07 8:05
Hakan Bulut14-Nov-07 8:05 
GeneralRe: Appoint help: Pin
led mike14-Nov-07 8:51
led mike14-Nov-07 8:51 
GeneralRe: Appoint help: Pin
Hakan Bulut15-Nov-07 5:39
Hakan Bulut15-Nov-07 5:39 

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.