Sign in to follow this  
Kryptus

[.net] Async Socket Flow of Data

Recommended Posts

I have the following line of code: mySocket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(this.ReadCallback), null); The problem I have is once this is used once, it's never used again obviously and continues on. What I'm asking is what is the best way to keep recieving data even after data has been recieved? mySocket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(this.ReadCallback), null); mySocket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(this.ReadCallback), null); mySocket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(this.ReadCallback), null); mySocket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(this.ReadCallback), null); This would recieve data 4 times as you can see. Would a loop then be wise or not? If I used a loop would I have to sleep threads or DoEvents? Please discuss.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Put the next BeginReceive in the ReadCallback method.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this