/// <summary> /// Connects to the MPD server who's IPEndPoint was set in the Server property. /// </summary> /// <exception cref="InvalidOperationException">If no IPEndPoint was set to the Server property.</exception> public void Connect() { if (this.ipEndPoint == null) { throw new InvalidOperationException("Server IPEndPoint not set."); } if (this.Connected) { throw new AlreadyConnectedException(); } if (m_SocketManager != null) { m_SocketManager.Dispose(); } m_SocketManager = new SocketManager(); m_SocketManager.Connect(ipEndPoint); string firstLine = m_SocketManager.ReadLine(); if (!firstLine.StartsWith(FIRST_LINE_PREFIX)) { this.Disconnect(); throw new InvalidDataException("Response of mpd does not start with \"" + FIRST_LINE_PREFIX + "\"."); } this.version = firstLine.Substring(FIRST_LINE_PREFIX.Length); //m_SocketManager.WriteLine(string.Empty); //this.readResponse(); MpdResponse response = Exec("commands"); m_Commands = response.getValueList(); if (this.OnConnected != null) { this.OnConnected.Invoke(this); } }
/// <summary> /// Connects to the MPD server who's IPEndPoint was set in the Server property. /// </summary> /// <exception cref="InvalidOperationException">If no IPEndPoint was set to the Server property.</exception> public void Connect() { if (this.ipEndPoint == null) throw new InvalidOperationException("Server IPEndPoint not set."); if (this.Connected) throw new AlreadyConnectedException(); if (m_SocketManager != null) { m_SocketManager.Dispose(); } m_SocketManager = new SocketManager(); m_SocketManager.Connect(ipEndPoint); string firstLine = m_SocketManager.ReadLine(); if (!firstLine.StartsWith(FIRST_LINE_PREFIX)) { this.Disconnect(); throw new InvalidDataException("Response of mpd does not start with \"" + FIRST_LINE_PREFIX + "\"."); } this.version = firstLine.Substring(FIRST_LINE_PREFIX.Length); //m_SocketManager.WriteLine(string.Empty); //this.readResponse(); MpdResponse response = Exec("commands"); m_Commands = response.getValueList(); if (this.OnConnected != null) this.OnConnected.Invoke(this); }