473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Async Socket , BeginReceive question .

Hi all ,
with BegeinReceive I can build async method of Socket Class
that Receive the data from the Socket Client .

My question is , if I have this code that create 3 Receive Async Call :

<code>
mySocket.BeginReceive(param1,param2,param3.....);
mySocket.BeginReceive(param1,param2,param3......);
mySocket.BeginReceive(param1,param2,param3......);

myThread.wait()
<code>

and If the Client Socket send my 3 async Message, what will happened ?

BeginReceive1, that receive message 1 ||| BeginReceive2, that receive message 2 ||| BeginReceive3, that receive message 3

or :
BeginReceive1, that receive Message 1
BeginReceive2, that receive Message 2
BeginReceive3, that receive Message 3

The 3 SendMessage is listen at the same time from server ?

or :

The server listen the Message1 with BeginReceive1,
server listen the Message 2 with BeginReceive2 when BeginReceive1 has finish to listen the Message 1
server listen the Message 3 with BeginReceive3 when BeginReceive 2 has finish to listen the Message 2 .

Thank all ,
dm






Nov 15 '05 #1
2 9193
"dream machine" <no@si.forse> wrote in message news:<O3**************@tk2msftngp13.phx.gbl>...
Hi all ,
with BegeinReceive I can build async method of Socket Class
that Receive the data from the Socket Client .

My question is , if I have this code that create 3 Receive Async Call :

<code>
mySocket.BeginReceive(param1,param2,param3.....);
mySocket.BeginReceive(param1,param2,param3......);
mySocket.BeginReceive(param1,param2,param3......);

myThread.wait()
<code>

and If the Client Socket send my 3 async Message, what will happened ?

dm -

This is somewhat of a trick question. Your last scenario is
correct, the three BeginReceive() methods will "stack up", and process
incoming data serially - one after the other. The first BeginReceive()
method will process whatever data is available on the socket first,
then the second BeginReceive() method will process any remaining data
(or new data on the socket), and finally, the third one will process.

The problem is that there is no control as to which BeginReceive()
method will process what data. TCP is not a message-oriented protocol,
it is stream-oriented. The three messages that are sent are not
guaranteed to be taken out of the socket buffer in the same format by
each of the three BeginReceive() methods that they were sent. Its
quite possible that the first BeginReceive() method will grab all of
message1, plus part of message2, then the second BeginReceive() method
grabs the end of message2 plus all of message3, leaving the last
BeginReceive() method never to complete, waiting for data. This would
make a nightmare situation trying to put all of the data back
together.

It is better to either mark your messages with boundaries or send
the message size before the actual message. That way the other end
knows when each message starts and stops, and can process the received
data properly. Hope this helps out some.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #2
Hi rich ,
thanks for your answer !

dm
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben | last post by:
I've written a fair amount of sockets code using the Winsock2 API, but I am having some trouble converting to the .Net Sockets API, specifically asynchronous sockets. What I have is a form that is...
1
by: Mark Smith | last post by:
Dear Readers, I am in the process of implementing a non-blocking ASYNC TCP client using the .Net socket class. I am a little confused by the MSDN example. I have pasted the code here. ...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
3
by: Eric | last post by:
I need to send an object between nodes on a network. Each node currently communicates fine with sending strings around but I can't figure out how to deserialize objects using the same basic...
1
by: Terry Olsen | last post by:
I'm trying to use Async Socket calls to create a tcp server. It goes into the listening correctly, but when I connect, it crashes with the following exception: An unhandled exception of type...
8
by: Dinsdale | last post by:
I am trying to write a Tcp "Server" that opens a class that wraps a tcp socket when a new connection is made (Listener.AcceptSocket()). Everything is going swimmingly except when I try to close the...
1
by: rockdale | last post by:
Hi, all Did not find a .Net Communication forum to post. I am soing a client/server message system and using C#.net socket and Async mode. Pretty much as described in article ...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
10
by: ColoradoGeiger | last post by:
I have a fairly standard server application that I am using asynchronous socket calls to make connections, send and receive data, and all of that jazz. No blocking methods was my goal in writing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.