Jump to content
  • Advertisement
Sign in to follow this  
Thevenin

[C#] Asynchronous .NET Sockets.

This topic is 4611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With the code below...
    /* 
     * Name: sSendPacket
     * Programmer: ***********.
     * Version: Janurary 2, 2006.
     * Description: This procedure sends the given data packet to the server.
    */
    public void sSendPacket(byte[] TheData)
    {
        MyGlobalSocket.BeginSend(TheData, 0, TheData.Length, SocketFlags.None,
            new AsyncCallback(sSendCallback), null);
    }

    /* 
     * Name: sSendCallback
     * Programmer: ***********.
     * Version: Janurary 2, 2006.
     * Description: This procedure lets us know that the packet has gone through the system.
    */
    public void sSendCallback(IAsyncResult MyAsyncResult)
    {
        /* Complete the send operation by ending the send. */
        int TheBytesSent = MyGlobalSocket.EndSend(MyAsyncResult);
    }
... if I did this...
void sSendEmAll()
{
     sSendPacket(ThePack);
     sSendPacket(TheIt);
     sSendPacket(TheThree);
}
... where the three separate parameters are byte arrays. Won't the sSendCallBack (when it gets the first pack) kill the second and third packets since its ending the send?

Share this post


Link to post
Share on other sites
Advertisement
It's my understanding that calling BeginSend creates a new thread, so by calling it three times you will have three independent threads. Thus the EndSend is tied only to its respective BeginSend.

Share this post


Link to post
Share on other sites
In general, when you call an asynchronous method (as in BeginSend), you create a new ThreadPool thread each time you begin the delegate invocation. See here for an overview of asynchronous methods.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!