Click here to Skip to main content
16,005,091 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CAsyncSocket --help please! Pin
csmithmaui20-Mar-07 8:31
csmithmaui20-Mar-07 8:31 
GeneralRe: CAsyncSocket --help please! Pin
Mark Salsbery20-Mar-07 8:39
Mark Salsbery20-Mar-07 8:39 
GeneralRe: CAsyncSocket --help please! Pin
csmithmaui20-Mar-07 10:01
csmithmaui20-Mar-07 10:01 
GeneralRe: CAsyncSocket --help please! Pin
Mark Salsbery20-Mar-07 10:10
Mark Salsbery20-Mar-07 10:10 
AnswerRe: CAsyncSocket --help please! Pin
Mark Salsbery16-Mar-07 14:34
Mark Salsbery16-Mar-07 14:34 
GeneralRe: CAsyncSocket --help please! Pin
csmithmaui16-Mar-07 15:05
csmithmaui16-Mar-07 15:05 
GeneralRe: CAsyncSocket --help please! Pin
Mark Salsbery16-Mar-07 15:16
Mark Salsbery16-Mar-07 15:16 
AnswerRe: CAsyncSocket --help please! Pin
Mark Salsbery16-Mar-07 15:35
Mark Salsbery16-Mar-07 15:35 
About the receive code...

From what I see above you are connecting, sending some data, and closing the socket. In that
case you are never going to get a FD_READ notification to trigger the OnReceive() call unless the
server happens to send some data fast enough at connect time. Unlikely.

There's two issues I see with your OnReceive handler, assuming it does get called before the
socket is closed:

1) You've maybe assumed you will receive the entire string in one call to Receive(). This is
not always the case. A successful recv() on a socket will return 1 or more bytes, up to the
number of bytes requested. If you receive one byte and you are expecting 10 bytes then you'll
need to handle that.

2) You are requesting 4096 bytes to receive. This is only ok (in your sample code) if you have a
communication protocol where the other end sends 4096 byte "packets" or you only plan on receiving
once before closing the socket. Generally with TCP you should know how many bytes to expect and
only receive that many, unless you cache received data and parse it later (or maybe on another
thread).

Mark



"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")

QuestionBuild Error - fatal error C1083 Pin
Reagan Conservative16-Mar-07 4:44
Reagan Conservative16-Mar-07 4:44 
AnswerRe: Build Error - fatal error C1083 Pin
Mike Dimmick16-Mar-07 5:03
Mike Dimmick16-Mar-07 5:03 
GeneralRe: Build Error - fatal error C1083 Pin
Reagan Conservative16-Mar-07 5:06
Reagan Conservative16-Mar-07 5:06 
AnswerRe: Build Error - fatal error C1083 Pin
vibindia16-Mar-07 5:05
vibindia16-Mar-07 5:05 
GeneralRe: Build Error - fatal error C1083 Pin
Reagan Conservative16-Mar-07 5:08
Reagan Conservative16-Mar-07 5:08 
GeneralRe: Build Error - fatal error C1083 Pin
vibindia16-Mar-07 5:18
vibindia16-Mar-07 5:18 
GeneralRe: Build Error - fatal error C1083 Pin
Reagan Conservative16-Mar-07 5:19
Reagan Conservative16-Mar-07 5:19 
QuestionWINDOWPLACEMENT Question Pin
Programm3r16-Mar-07 4:30
Programm3r16-Mar-07 4:30 
AnswerRe: WINDOWPLACEMENT Question Pin
Programm3r16-Mar-07 4:42
Programm3r16-Mar-07 4:42 
AnswerRe: WINDOWPLACEMENT Question Pin
JudyL_MD16-Mar-07 4:51
JudyL_MD16-Mar-07 4:51 
QuestionHtmlHelp with VC6 ? Pin
Dave_16-Mar-07 4:14
Dave_16-Mar-07 4:14 
AnswerRe: HtmlHelp with VC6 ? Pin
Dave_16-Mar-07 5:27
Dave_16-Mar-07 5:27 
QuestionDebug vs Release Pin
vibindia16-Mar-07 3:45
vibindia16-Mar-07 3:45 
AnswerRe: Debug vs Release Pin
James R. Twine16-Mar-07 3:49
James R. Twine16-Mar-07 3:49 
GeneralRe: Debug vs Release Pin
vibindia16-Mar-07 3:56
vibindia16-Mar-07 3:56 
AnswerRe: Debug vs Release Pin
prasad_som16-Mar-07 4:07
prasad_som16-Mar-07 4:07 
GeneralRe: Debug vs Release Pin
Sebastian Schneider16-Mar-07 4:12
Sebastian Schneider16-Mar-07 4:12 

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.