473,890 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.BeginR eceive(param1,p aram2,param3... ..);
mySocket.BeginR eceive(param1,p aram2,param3... ...);
mySocket.BeginR eceive(param1,p aram2,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 9238
"dream machine" <no@si.forse> wrote in message news:<O3******* *******@tk2msft ngp13.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.BeginR eceive(param1,p aram2,param3... ..);
mySocket.BeginR eceive(param1,p aram2,param3... ...);
mySocket.BeginR eceive(param1,p aram2,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
2431
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 both a client and a server. When the form starts I create a listening socket and call Socket.BeginAccept(). When a client connects my accept function is called, and it is on a separate thread. After I accept the client connection I connect to...
1
13750
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. private static void ReceiveCallback( IAsyncResult ar ) { try { // Retrieve the state object and the client socket // from the asynchronous state object.
5
11742
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 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
3
8060
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 infrastructure. I'm currently using MS's basic server example for my code: public static void AcceptCallback(IAsyncResult ar) { // Signal the main thread to continue. allDone.Set();
1
1298
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 'System.InvalidOperationException' occurred in system.dll Additional information: AcceptCallback There is no source code available for the current location. Here's the code. Hopefully someone can help me out.
8
11033
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 socket during a read and I get the following error: <error_msg> An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll Additional information: The I/O operation has been aborted because of
1
2539
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 http://www.developerfusion.co.uk/show/3997/3/
10
4521
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 consideration here is that it is supplied to the AsyncOperationManager.CreateOperation(userSuppliedState) method... with userSuppliedState being, more or less, a taskId. In this case, the userSuppliedState {really taskId} is of the object type,...
10
8085
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 this and it's gone very well so far. But coming from the blocking world, I want to have some timeouts on my receive routines and I after reading a lot on MSDN and here, I get the impression that once I set one of these Begin... methods a running...
0
9822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10462
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8016
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.