Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So if I get it right, you want to re-start <code>Accept</code> as soon as a socket connection is received, and not wait until <code>Accept</code> is done, and that's why you don't use the sync version of <code>Accept</code>. </p> <p>So you are saying that it does not fire your Accept method when you connect a socket to the specified address and port? Because that's what Accept does: it accepts a new incoming connection, waiting until a client connects. So that may be why you are thinking that it "crashed" and why it never reaches your code in your Accept method.</p> <p>Hint: maybe also have a look at <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.acceptasync.aspx" rel="nofollow noreferrer"><code>Socket.AcceptAsync</code></a></p> <p><strong>Edit:</strong> To set up an async server listening to incoming connections, you don't need any ManualWaitEvent:</p> <pre><code>internal void Initialize(int port,string IP) { IPEndPoint _Point = new IPEndPoint(IPAddress.Parse(IP), port); Socket _Accpt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _Accpt.Bind(_Point); _Accpt.Listen(2); _Accpt.BeginAccept(null, 0, new AsyncCallback(Accept), _Accpt); } private void Accept(IAsyncResult async) { Socket _Accpt = (Socket)async.AsyncState; Socket _Handler; try { _Handler = _Accpt.EndAccept(async); } finally { _Accpt.BeginAccept(null, 0, new AsyncCallback(Accept), _Accpt); } StateObject _State = new StateObject(); _State.workSocket = _Handler; _Handler.BeginReceive(_State.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), _State); } </code></pre> <p><strong>Note:</strong> You will also need an exit condition, so that the BeginAccept is not called (for instance when you want to shut down the server).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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