private void AssociationReleaseReceived(byte [] pdu) { Dump("<< A-RELEASE-RQ ...", pdu); //#if DEBUG // if (number != 0) Console.WriteLine("association {0,4} closed", number); //#endif AssociationReleasePdu release = new AssociationReleasePdu(ProtocolDataUnit.Type.A_RELEASE_RP); State = State.Closed; Send("A-RELEASE-RP", release); }
/// <summary> /// Closes the Association. /// </summary> /// <returns>True if we get a response, False otherwise.</returns> public bool Close() { bool result = true; if (!disposed) { try { if (IsOpen()) { AssociationReleasePdu release = new AssociationReleasePdu(ProtocolDataUnit.Type.A_RELEASE_RQ); MemoryStream memory = new MemoryStream(); release.Write(memory); Dump(">> " + "A-RELEASE-RQ", memory.ToArray()); NetworkStream output = new NetworkStream(socket, FileAccess.Write, false); State = State.Closing; output.Write(memory.ToArray(), 0, (int)memory.Length); // get response if (!completeEvent.WaitOne(timeout, false)) { result = false; } } // close socket if (socket.Connected) { socket.Close(); if (!threadEvent.WaitOne(timeout, false)) { Logging.Log("Background thread did not complete."); } } } catch (Exception e) { State = State.Closed; Logging.Log(e.Message); result = false; } } State = State.Closed; return(result); }
private void OnClosing(byte[] pdu) { // parse response MemoryStream memory = new MemoryStream(pdu, 0, pdu.Length); AssociationReleasePdu response = new AssociationReleasePdu(); response.Read(memory); switch ((ProtocolDataUnit.Type)response.PduType) { case ProtocolDataUnit.Type.A_RELEASE_RP: State = State.Closed; Dump("<< A-RELEASE-RP", pdu); break; default: State = State.Closed; Dump(String.Format("<< UNEXPECTED PDU(0x{0:x4})", (byte)response.PduType), pdu); break; } completeEvent.Set(); }