473,805 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Q] EndReceive Asynchron C# Socket

Hi,

I'm implementing an asynchron socket Receiving method and I have a
question about EndReceive.

Read()
{
Socket.BeginRec eive(buf,0,buf. Length,0,new
AsyncCallback(R eadCallback),dp );
}

ReadCallback(IA syncResult asyncRes)
{
...
int bytesRead = Socket.EndRecei ve(asyncRes);
...
}

My question is now, what happens if I try to receive a datapacket
which is greater than the buffer buf? EndReceive returns when when the
buffer buf is full. Can I call EndReceive again? or should I restart
Read()? But how can I know that there are datas waiting for reading?

Thanks
André Betz
http://www.andrebetz.de
Nov 16 '05 #1
1 4224
Hi,
EndReceive returns when when the buffer buf is full. No, it may retrun less bytes than buffer, because of it ALWAYS see hwo much
int bytesRead = Socket.EndRecei ve recived.
Can I call EndReceive again? or should I restart No, you must start from BeginRecieve again
Read()? But how can I know that there are datas waiting for reading? You don't need to know that, BeginRecieve waits data to arrive.

"Andre" <sk******@gmx.d e> wrote in message
news:be******** *************** ***@posting.goo gle.com... Hi,

I'm implementing an asynchron socket Receiving method and I have a
question about EndReceive.

Read()
{
Socket.BeginRec eive(buf,0,buf. Length,0,new
AsyncCallback(R eadCallback),dp );
}

ReadCallback(IA syncResult asyncRes)
{
...
int bytesRead = Socket.EndRecei ve(asyncRes);
...
}

My question is now, what happens if I try to receive a datapacket
which is greater than the buffer buf? EndReceive returns when when the
buffer buf is full. Can I call EndReceive again? or should I restart
Read()? But how can I know that there are datas waiting for reading?

Thanks
André Betz
http://www.andrebetz.de

Nov 16 '05 #2

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

Similar topics

8
9291
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added it, and my code now works simply and as expected. def close(self):
4
3797
by: Ken Foster | last post by:
I have a Socket based application using the asynchronous Sends and Receives of the Socket class. I send out XML strings using BeginSend/EndSend from a client end point, the server side does a BeginReceive/EndReceive. I knew a message could be split up between Receives and I look for an end of message marker (and continue receiving if not there) before processing the complete message. However I was told (on this board I think) that I would...
3
3993
by: Chotchkie | last post by:
Hello, I am running into a problem with Asynchronous socket communication. I am developing a simple telnet client to interact with unix. I am parsing received data for prompts and sending data on found. Problem is, that sometimes EndReceive returns only a few bytes, much less than what is in the buffer. Since I am parsing what is in the buffer up to how large bytes received is, I end up skipping data. Odd thing is that it works 1/2...
0
960
by: Ken Foster | last post by:
I'm creating a system wide (distributed) Publish/Subscribe Event Broker using ..NET Sockets as the transport mechanism. I'm doing all my connects/accepts/sends/receives asynchronously (well, not all, but thats beside the point really). I also have an EventBroker that all clients connect to and the EventBroker holds the open socket connections to communicate with. My problem is, how do I know when my EndReceive call has finished a message?...
1
1995
by: Ken Foster | last post by:
I have a Socket based application using the asynchronous Sends and Receives of the Socket class. I send out XML strings using BeginSend/EndSend from a client end point, the server side does a BeginReceive/EndReceive. I knew a message could be split up between Receives and I look for an end of message marker (and continue receiving if not there) before processing the complete message. However I was told (on this board I think) that I would...
1
2561
by: Marty | last post by:
Hi, I have a socket that always seek for incoming data. Between Point A and Point B, the socket (mySocket is closed and assigned to nothing in another part of my program (happen when a connection is broken). So regurlarly when a socket is closed, it create an error somewhere in this routine, even if I check if the socket is nothing or not, and connected or not (I also tried to check before doing the beginreceive)
7
3195
by: darthghandi | last post by:
I am having mixed results with asynchronous socket receives. Sometimes I get the right information back from the buffer, other times I get some of the data that should be in the buffer printed out to the console. That data is printed out to the console before I even call Socket.EndReceive(). After that call, I get the rest of the data that wasn't printed out to the console in the buffer. Anyone have any idea what is going on? Here's...
2
3160
by: O.B. | last post by:
I have a C# Socket configured for streaming TCP. Upon making a valid connection, I have an asynchronous callback configured using BeginReceive. Within the BeginReceive declaration, I set the socket flags to SocketFlags.Partial to allow my callback to be invoked as soon as it arrives rather than waiting for the receive buffer to fill up. The problem I am having is that when I invoke the Socket.EndReceive(asyncResult) operation within...
0
1873
by: foahchon | last post by:
Hi, I'm trying to write a receive loop in my socket class that will receive what data is in the buffer, call an event to let the user know that there's new data, and then receive the rest of the data. It kinda almost works; it receives much of the data, but seems to miss the last packet or two. Here is the code in the loop: private void OnSockReceive(IAsyncResult ar) { try { if...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10364
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...
1
10370
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
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...
1
7649
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
6876
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
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
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.