Problem with AcceptCallback closing server socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    #1

    Problem with AcceptCallback closing server socket

    Having:Socket mysocket = new Socket
    (AddressFamily. InterNetwork, SocketType.Stre am,
    ProtocolType.Tc p);

    I cannot execute mysocket.Close( ) after executing
    mysocket.BeginA ccept(new AsyncCallback(S erverAcceptConn )..

    The system complains giving a hint "AcceptCallback "

    What should I execute before closing to not have this
    error message?
    Thanks.

  • Rich Blum

    #2
    Re: Problem with AcceptCallback closing server socket

    "David" <dave.spector@e ds.com> wrote in message news:<043101c35 b81$f16fca50$a1 01280a@phx.gbl> ...[color=blue]
    > Having:Socket mysocket = new Socket
    > (AddressFamily. InterNetwork, SocketType.Stre am,
    > ProtocolType.Tc p);
    >
    > I cannot execute mysocket.Close( ) after executing
    > mysocket.BeginA ccept(new AsyncCallback(S erverAcceptConn )..
    >
    > The system complains giving a hint "AcceptCallback "
    >
    > What should I execute before closing to not have this
    > error message?
    >[/color]
    David -

    I made a response to this earlier, but I don't see it posted, so
    either something went wrong, or you will see two responses from me.
    Sorry about that.

    When the socket object is closed with an outstanding BeginAccept()
    method, the AsyncCallback method will be automatically fired, and the
    EndAccept() method will throw an ObjectDisposedE xception. You need to
    catch that using a try-catch block, and handle it accordingly. Hope
    this helps solve your problem.

    Rich Blum - Author
    "C# Network Programming" (Sybex)

    "Network Performance Open Source Toolkit" (Wiley)

    Comment

    Working...