/// <summary> /// Accepts an incoming connection and starts the data listener. /// </summary> /// <param name="client">The client to accept.</param> /// <returns>true on success; otherwise false.</returns> public bool Accept(Socket client) { if (Parent.State != State.Closed) { throw new WinsockException("Cannot accept a connection while the State is not closed."); } try { socket = new AsyncSocket(client); Parent.ChangeLocalPort(LocalEndPoint.Port); Parent.ChangeRemoteHost(RemoteEndPoint); Parent.ChangeRemotePort(RemoteEndPoint.Port); Parent.ChangeState(State.Connected); Parent.OnConnected(RemoteEndPoint); BeginReceive(true); return(true); } catch (Exception ex) { Parent.OnErrorReceived(Parent, ex.AsEventArgs()); return(false); } }