how to receive data from several sockets in terms of multithreading?
<p>I want to rephrase my previous question <a href="http://stackoverflow.com/questions/9727521/should-i-replace-all-my-new-thread-with-task-factory-startnew">Should I replace all my &quot;new Thread&quot; with &quot;Task.Factory.StartNew&quot;?</a></p>

<p>I need to listen for several udp sockets</p>

<pre><code>................
s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
........

public void Receive()
{
    byte[] buffer = new byte[65536];
    while (true)
    {
        try
        {
            count = s.Receive(buffer);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            return;
        }
        if (count &gt; 0)
        {
            OnNewDatagram(new NewDatagramEventArgs(buffer, count));
        }
    }
}
</code></pre>

<p>So I need to launch several "Receive()" methods (one for each socket).
Now I'm using one Thread for one socket:</p>

<pre><code>socketA = new...
....
threadA = new Thread(Receive);
.....
threadA.Start();

socketB = new...
....
threadB = new Thread(Receive);
.....
threadB.Start();
</code></pre>

<p>What should I use:</p>

<ul>
<li>one thread for one socket</li>
<li>one thread for all sockets(how?)</li>
<li>one task for all sockets</li>
<li>one task for one socket</li>
<li>other?</li>
</ul>

<p><strong>upd</strong> I have only 2-3 sockets, so it's probably better to use one-socket-one-thread model instead of Socket.Select... or one-socket-one-task model?</p>
