Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As per my recommendation please use new Async form of <code>XXXReceive</code> and 'XXXSend' (where XXX stands for <code>Begin</code> and <code>End</code>), the new methods available are <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receiveasync.aspx" rel="nofollow">ReceiveAsync</a> and <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.sendasync.aspx" rel="nofollow">SendAsync</a> methods which uses <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx" rel="nofollow">SocketAsyncEventArgs</a> to pass the socket and other information on the callbacks event handlers.</p> <p>I had seen a good working example of socket client and server on msdn archive which was scalable upto 500 connections (As I had tested in one of project adaptation from it) but currently I am not able to find that link from googling.. but here is another link from msdn archive on the same topic hopefully it will help you - <a href="http://msdn.microsoft.com/en-us/magazine/cc300760.aspx" rel="nofollow">Get Closer to the Wire with High-Performance Sockets in .NET</a>..</p> <h2>UPDATE</h2> <p>First of all <strong>I</strong> can only provide you idea to final implementation and if possible some short example code snippets. ok here I go with more details </p> <p><strong>I think you can jump to last paragraph's link. ;)</strong></p> <p>Let me highlight once because I want to, I said <code>SendAsync</code> and <code>ReceiveAsync</code> not <code>BeginReceive/EndReceive</code> and <code>BeginSend/EndSend</code> i.e. Event-based Async Pattern (EAP) </p> <blockquote> <p>Benefit of using Async form of Socket methods is that they are exception-less approach to socket programming which can prove faster than BeginSend/EndSend methods.</p> </blockquote> <p>Here is the link for the sample which I have found to be useful upto 500 PARALLEL connections - <a href="http://archive.msdn.microsoft.com/nclsamples/Wiki/View.aspx?title=Socket%20Performance" rel="nofollow">Networking Samples for .NET v4.0</a></p> <p>For you need to use await/async feature of .NET 4.5. Here is the .NET 4.5 code snippet showing usage of <code>WebSocket</code> class which of can be adapted to <code>Socket</code> implementations also - <a href="http://www.asp.net/vnext/overview/aspnet/whats-new#_Toc318097383" rel="nofollow">Support for WebSockets Protocol</a> (I guess WebSocket's <code>AspNetWebSocketContext</code> will be Socket's <code>SocketAsyncEventArgs</code>)</p> <p><em>I found <a href="http://blogs.msdn.com/b/pfxteam/archive/2011/12/15/10248293.aspx" rel="nofollow">Awaiting Socket Operations</a> sample code from <a href="http://blogs.msdn.com/b/pfxteam" rel="nofollow">MSDN - Parallel Programming team blog</a> which can be useful to use to implement await/async from .NET 4.5 framework.</em></p> <p>I hope this proves helpful to you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload