# [C#] Asynchronous .NET Sockets.

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

## 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 on other sites
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 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 9
• 25