I'm new to this forum but have been a fan for several years of MPD & GMPC on Linux. Recently took up the task to build a website with similar look & feel to GMPC. As a teacher I need a nice example of an Angular website and this is a nice 'pet project'.

All is going very well up until I used the command 'list Artist' to list all the artists. If I use the MPC command line tool like this:

) I get e.g. 1500 artists. However, when using PHP and a socket (fsockopen) only 16384 are received at max. And this leads up to about 600-650 artists being listed. I detect an EOF (feof function used) and stop reading. Reopening the socket does not help.

I tried a lot and even installed the last MPD version (0.21) on my dev-machine from source (hurrah!). Changed the MPD config

Music Player Daemon 0.21.13 (0.21.13)
Copyright 2003-2007 Warren Dukes <warren.dukes@gmail.com>
Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

1. It sends the newline twice, which means MPD closes the connection due to a malformed command line. This is what may have caused the transfer to be closed.
2. It uses binary mode for a text connection.
3. It keeps on receiving forever until MPD closes the connection, and this will eventually block.
4. It doesn't put a limit on the allocated memory, possibly consuming gigabytes of RAM if a malicious server decides to send so much data.
5. It ignores the end of the response; it has no understanding of the MPD protocol.

Don't reimplement the MPD protocol, because this will waste time and lets you repeat mistakes other people already did - instead, check if a MPD client library is available for the language of your choice.

@Max a great thanks for taking the time to inspect my code. The first problem seems to be the culprit. And the rest was there because I was so desperate to get it working. I removed the extra newline and it worked (sort of).

I totally agree with you not inventing something that can be obtained from the community. However, I was using this as an educational learning project for implementing e.g. Angular, REST API, design patterns etc. That's the main reason.

Regarding point nr 5: In this version it indeed does not understand. In my original version it kept on reading until the "OK" message was found. However, in fixing the problem I totally refactored my code, because I didn't understand the socket problem.