473,395 Members | 1,885 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.

BeginReceive, and zero-sized packets

Hi all,

I am writing a small application that listens for any incoming message indefinitely, via BeginReceive. I did this by having the Receive callback function call the method that starts listening, after it processes the received data. (There probably is a better way to do this, but...)

My problem is, when the connection gets closed by the other side, I get a zero sized packet, and then I encounter an infinite loop of sorts.

Any ideas on how to circumvent this? Thanks in advance.
May 19 '07 #1
2 1048
kenobewan
4,871 Expert 4TB
Welcome to the site. I believe you could check for zero packets and take an alternate action.
May 19 '07 #2
Welcome to the site. I believe you could check for zero packets and take an alternate action.
Thanks.

I have this block at the end of the callback

if (...) {.....}
else if (...) {...}
else if (sb.length ==0)
{
//Do nothing
}

StartListening();
}

What happens is, it does nothing, then starts listening again. Then immediately gets an empty packet, ignores it, starts listening, ad infinitum. This is what I'd like to avoid.
May 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lee Gillie | last post by:
What is the proper way to cancel a pending BeginReceive/EndReceive ? Can it be done without generating an exception ? Currently I shutdown and close the socket. The blocking "EndReceive" throws...
2
by: dream machine | last post by:
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 : ...
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. ...
6
by: Steve Richter | last post by:
I dont get the point of socket.BeginReceive and socket.EndReceive. As I understand it, BeginReceive will start a 2nd thread, call the ReceiveCallback delegate in the 2nd thread, then block until...
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...
4
by: Ryan Liu | last post by:
TcpClient has a method called GetworkStream GetStream(); So in other words, there is only one stream associate with it for input and output, right? So while it is receiving, it can not send, and...
2
by: Marcel Brekelmans | last post by:
Hi, I use a socket to receive data from a certain process. I use the asynchronous operations BeginReceive() and EndReceive(), with a callback in BeginReceive. Now all documentation says that the...
9
by: semedao | last post by:
Hi, I am using sync and async operations on the same socket. generally I want the socket to wait on BeginReceive and to not block the object thread. but in some cases I want to stop the...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
2
by: O.B. | last post by:
In the following code snippet, the thread successfully makes it to the line where it waits for data to be received. Then the client closes the connection. The thread wakes up and returns from the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
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
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...
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.