Yes thanks, that is what I was looking for. I have copied some code and pasted it below, to show what I am going to try. I’ve also highlighted the two areas that I could still use some help with. • *MPD_LOCAL_SOCKET_ADDRESS: *I believe linux SS command should show this. $ ss -x -a // local socket address already setup between MPD and upmdpcli • *STOP_COMMAND_SEQUENCE: *any advice on string(s) to write to socket to mimic command sequence that would be received by MPD when JRiver is playing and the STOP button is pressed.

Note:  We are using upmpdci, the  UPnP Media Renderer front-end for MPD.

// Includes
...

// File scope
int socket_fd;

// Generic function to show example calls
void foo(void)
{
      …
      // call to setup socket
socket_setup( *MPD_LOCAL_SOCKET_ADDRESSS*); // Use local socket address already setup between MPD and upmdpcli
    ...
    // call to write command sequence
write_cmd_to_socket(*STOP_COMMAND_SEQUENCE);*// command sequence that would be received by MPD when JRiver is playing and STOP button is pressed
    ….
}

void write_cmd_to_socket (const char* cmd)
{
        int length = strlen(cmd) + 1;
        write(socket_fd, cmd, length);
}

void socket_setup (const char* socket_address)
 {
      struct sockaddr_un name;

      /* Create socket. */
     socket_fd = socket (PF_LOCAL, SOCK_STREAM, 0);

     /* Store the server’s name in the socket address. */
     name.sun_family = AF_LOCAL;
     strcpy (name.sun_path, socket_address);

     /* Connect the socket. */
     connect (socket_fd, &name, SUN_LEN (&name));

    close (socket_fd);
    return 0;
}

Ed

-------------------------------------------------------------------------------------------------------------------------
On 8/11/2017 5:19 PM, Kurt Van Dijck wrote:
    I am trying to allow a second application to send a STOP command to
    MPD, using the existing local socket created by MPD.  I would like to
    allow a form of Convenience Switching.  So if music is playing through
    MPD from an MPD client (JRiver).  The second application could then
    STOP MPD play safely(as though command came from MPD client (Jriver).
    I have attached a terminal screen shot  below, showing mpd socket
    assignment.

A snippet I wrote recently:

static int connect_uri(const char *host, int port, int preferred_type)
{
        int sock;

        if (*host == '@' || *host == '/') {
                /* unix socket */
                struct sockaddr_un addr = {
                        .sun_family = AF_UNIX,
                };
                int socklen;

                strcpy(addr.sun_path, host);
                socklen = strlen(host) + offsetof(struct sockaddr_un, sun_path);

                sock = socket(AF_UNIX, preferred_type, 0);
                if (sock < 0)
                        mylog(LOG_ERR, "socket AF_UNIX ...: %s", ESTR(errno));
                if (connect(sock, (void *)&addr, socklen) < 0)
                        mylog(LOG_ERR, "bind %s: %s", host, ESTR(errno));
                return sock;
        }

The remainder goes via ip sockets, which is not necessarily what you
want.

Is this what you were looking for?

Kurt




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
_______________________________________________
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to