473,378 Members | 1,390 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,378 software developers and data experts.

[Q] EndReceive Asynchron C# Socket

Hi,

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

Read()
{
Socket.BeginReceive(buf,0,buf.Length,0,new
AsyncCallback(ReadCallback),dp);
}

ReadCallback(IAsyncResult asyncRes)
{
...
int bytesRead = Socket.EndReceive(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 4202
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.EndReceive 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.de> wrote in message
news:be**************************@posting.google.c om... Hi,

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

Read()
{
Socket.BeginReceive(buf,0,buf.Length,0,new
AsyncCallback(ReadCallback),dp);
}

ReadCallback(IAsyncResult asyncRes)
{
...
int bytesRead = Socket.EndReceive(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
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...
4
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...
3
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...
0
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...
1
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...
1
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...
7
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...
2
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.