Click here to Skip to main content
15,868,016 members
Home / Discussions / C#
   

C#

 
GeneralThanks a lot Pin
Abbas_here7-Sep-09 1:37
Abbas_here7-Sep-09 1:37 
AnswerRe: CSV file Pin
Vivek Vijayan7-Sep-09 1:25
Vivek Vijayan7-Sep-09 1:25 
AnswerRe: CSV file Pin
DaveyM697-Sep-09 1:35
professionalDaveyM697-Sep-09 1:35 
AnswerRe: CSV file Pin
Henry Minute9-Sep-09 11:40
Henry Minute9-Sep-09 11:40 
GeneralRe: CSV file Pin
Abbas_here9-Sep-09 20:30
Abbas_here9-Sep-09 20:30 
QuestionHow to stream an FLV vdo on a device application Pin
Vivek Vijayan7-Sep-09 1:00
Vivek Vijayan7-Sep-09 1:00 
QuestionC# Socket.BeginReceive/EndReceive Pin
staticv7-Sep-09 0:24
staticv7-Sep-09 0:24 
AnswerRe: C# Socket.BeginReceive/EndReceive Pin
Luc Pattyn7-Sep-09 2:31
sitebuilderLuc Pattyn7-Sep-09 2:31 
Hi,

According to the documentation, each BeginXxx needs a corresponding EndXxx, and typically that can be handled by the callback method.

I can't tell you what exactly is wrong in your code, however it is my impression your code is too complex and not sufficiently safe. I would code this more defensively, and avoid all the global variables your class seems to hold (receiveDataBuffer, bytesReceived, messageLengthReceived).

These are things I would do differently:

1.
I would create a little class holding clientSocket, the receive data buffer, an index into it;
then create two instances (one for length, one for data) of it for each length+data communication, and pass them as the last parameter to the BeginReceive calls (and retrieve it from the EndReceive calls).

2.
I would completely split the WaitForData() method into a WaitForLength method and a WaitForData method.
And I would completely split the RecieveComplete() method into a ReceivedLength method and a ReceivedData method.

(2) makes messageLengthReceived redundant.
(1) avoids the risk of receiveDataBuffer and bytesReceived to contain data belonging to another ongoing communication.

I am not saying the problem will be solved by doing this, I do claim the code would be more robust and easier to read, and either the problem is gone, or you'll have a better chance of locating the problem.

FWIW: I'm puzzled by AsyncClient.BUFFER_SIZE, it appears only once in the code shown; is it the size required to hold the length part only?

Hope this helps.

Luc Pattyn
Badger | [badger,badger,badger,badger...] Jig | [Dance] Badger | [badger,badger,badger,badger...] Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.Jig | [Dance] Badger | [badger,badger,badger,badger...] Jig | [Dance]

GeneralRe: C# Socket.BeginReceive/EndReceive Pin
staticv7-Sep-09 22:02
staticv7-Sep-09 22:02 
QuestionConvert doc file to image file Pin
Member 46007157-Sep-09 0:19
Member 46007157-Sep-09 0:19 
AnswerRe: Convert doc file to image file Pin
Christian Graus7-Sep-09 0:36
protectorChristian Graus7-Sep-09 0:36 
QuestionPlease Help Pin
itsravie6-Sep-09 23:59
itsravie6-Sep-09 23:59 
AnswerRe: Please Help [modified] Pin
DaveyM697-Sep-09 0:05
professionalDaveyM697-Sep-09 0:05 
AnswerRe: Please Help Pin
Nicholas Butler7-Sep-09 0:15
sitebuilderNicholas Butler7-Sep-09 0:15 
GeneralRe: Please Help Pin
itsravie7-Sep-09 0:17
itsravie7-Sep-09 0:17 
GeneralRe: Please Help Pin
Kevin McFarlane7-Sep-09 0:19
Kevin McFarlane7-Sep-09 0:19 
GeneralRe: Please Help Pin
itsravie7-Sep-09 0:38
itsravie7-Sep-09 0:38 
GeneralRe: Please Help Pin
Not Active7-Sep-09 2:59
mentorNot Active7-Sep-09 2:59 
GeneralRe: Please Help Pin
Nicholas Butler7-Sep-09 0:20
sitebuilderNicholas Butler7-Sep-09 0:20 
GeneralRe: Please Help Pin
DaveyM697-Sep-09 0:23
professionalDaveyM697-Sep-09 0:23 
GeneralRe: Please Help Pin
Nicholas Butler7-Sep-09 0:39
sitebuilderNicholas Butler7-Sep-09 0:39 
QuestionProblem in setup project [modified] Pin
xodeblack6-Sep-09 23:55
xodeblack6-Sep-09 23:55 
AnswerRe: Problem in setup project Pin
Keith Barrow7-Sep-09 0:02
professionalKeith Barrow7-Sep-09 0:02 
GeneralRe: Problem in setup project Pin
xodeblack7-Sep-09 0:09
xodeblack7-Sep-09 0:09 
GeneralRe: Problem in setup project Pin
Keith Barrow7-Sep-09 0:14
professionalKeith Barrow7-Sep-09 0:14 

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.